import sys
import uix
import uiutil
import uthread
import util
import log
import blue
import menu
import form
import xtriui
import moniker
import service
import destiny
import chat
import types
import state
import trinity
import base
import draw
import fleetcommon
import math
import inventoryFlagsCommon
import uiconst
import copy
import pos
import uicls
import entities
from collections import defaultdict

class MenuSvc(service.Service):
    __guid__ = 'svc.menu'
    __update_on_reload__ = 0
    __dependencies__ = ['account',
     'addressbook',
     'pvptrade',
     'LSC',
     'fleet',
     'pwn',
     'godma',
     'michelle',
     'faction',
     'manufacturing']
    __notifyevents__ = ['DoBallRemove', 'OnSessionChanged']

    def Run(self, memStream = None):
        self.primedMoons = {}
        self.bypassCommonFilter = [mls.UI_CMD_REPACKAGE]
        self.multiFunctions = [mls.UI_CMD_REPACKAGE,
         mls.UI_CMD_BREAK,
         mls.UI_CMD_REFINE,
         mls.UI_CMD_REPROCESS,
         mls.UI_CMD_LAUNCHDRONES,
         mls.UI_CMD_TRASHIT,
         mls.UI_CMD_SPLITSTACK,
         mls.UI_CMD_TOHANGARANDREFINE,
         (mls.UI_SHARED_SQ_TRAINNOW % {'num': 1}),
         mls.UI_SHARED_SKILLS_INJECT,
         mls.UI_CMD_PLUGIN,
         mls.UI_CMD_SETNAME,
         mls.UI_CMD_ASSEMBLECONTAINER,
         mls.UI_CMD_ASSEMBLEPLATFORM,
         mls.UI_CMD_OPENCONTAINER,
         mls.UI_CMD_ASSEMBLESHIP,
         mls.UI_CMD_FITTOACTIVESHIP,
         mls.UI_CMD_OPENDRONEBAY,
         mls.UI_CMD_OPENCARGOHOLD,
         mls.UI_CMD_LAUNCHFORSELF,
         mls.UI_CMD_LAUNCHFORCORP,
         mls.UI_CMD_JETTISON,
         mls.UI_CMD_LAUNCHSHIP,
         mls.UI_CMD_TAKEOUTTRASH,
         mls.UI_CMD_ENGAGETARGET,
         mls.UI_CMD_MINE,
         mls.UI_CMD_MINEREPEATEDLY,
         mls.UI_CMD_RETURNANDORBIT,
         mls.UI_CMD_RETURNTODRONEBAY,
         mls.UI_CMD_DELEGATECONTROL,
         mls.UI_CMD_ASSIST,
         mls.UI_CMD_GUARD,
         mls.UI_CMD_RETURNCONTROL,
         mls.UI_CMD_ABANDONDRONE,
         mls.UI_CMD_SCOOPTODRONEBAY,
         mls.UI_CMD_LOCKITEM,
         mls.UI_CMD_UNLOCKITEM,
         mls.UI_CMD_REPROCESS,
         mls.UI_CMD_MOVETODRONEBAY,
         mls.UI_GENERIC_MEMBER,
         mls.UI_CMD_CONTRACTTHISITEM,
         mls.UI_CMD_AWARDDECORATION,
         mls.UI_CMD_SENDMESSAGE,
         mls.UI_CMD_REMOVEFROMADDRESSBOOK,
         mls.UI_CMD_ADDTOADDRESSBOOK,
         mls.UI_CMD_FORMFLEETWITH,
         mls.UI_CMD_CAPTUREPORTRAIT,
         mls.UI_CMD_LAUNCHSHIP,
         mls.UI_CMD_LAUNCHSHIPFROMBAY,
         mls.UI_CMD_GETREPAIRQUOTE,
         mls.UI_PI_ACCESSCARGOLINK]
        self.multiFunctionFunctions = [self.DeliverToCorpHangarFolder]



    def Stop(self, *args):
        self.expandTimer = None



    def OnSessionChanged(self, isremote, session, change):
        self.expandTimer = None
        menu.KillAllMenus()
        if ('solarsystemid' in change):
            self.PrimeMoons()



    def DoBallRemove(self, ball, slimItem, terminal):
        if (ball is None):
            return 
        self.LogInfo('DoBallRemove::menusvc', ball.id)
        if ((sm.GetService('camera').LookingAt() == ball.id) and (ball.id != eve.session.shipid)):
            if terminal:
                uthread.new(self.ResetCameraDelayed, ball.id)
            else:
                sm.GetService('camera').LookAt(eve.session.shipid)



    def ResetCameraDelayed(self, id):
        blue.pyos.synchro.Sleep(5000)
        if (sm.GetService('camera').LookingAt() == id):
            sm.GetService('camera').LookAt(eve.session.shipid)



    def TryExpandActionMenu(self, *args):
        if (eve.triapp.uilib.Key(uix.VK_MENU) or eve.triapp.uilib.Key(uix.VK_CONTROL)):
            return 0
        else:
            wantedBtn = settings.user.ui.Get('actionmenuBtn', 0)
            if ((not eve.triapp.uilib.rightbtn) and ((eve.triapp.uilib.leftbtn and (wantedBtn == 0)) or (eve.triapp.uilib.midbtn and (wantedBtn == 2)))):
                self.expandTimer = base.AutoTimer(settings.user.ui.Get('actionMenuExpandTime', 150), self._TryExpandActionMenu, *args)
                return 1
            return 0



    def _TryExpandActionMenu(self, itemID, x, y, wnd):
        self.expandTimer = None
        eve.triapp.uilib.ReleaseCapture()
        if wnd.destroyed:
            return 
        v = trinity.TriVector(float((eve.triapp.uilib.x - x)), float((eve.triapp.uilib.y - y)), 0.0)
        if int((v.Length() > 12)):
            return 
        slimItem = uix.GetBallparkRecord(itemID)
        if not slimItem:
            return 
        self.ExpandActionMenu(slimItem)



    def ExpandActionMenu(self, slimItem, centerItem = None):
        uix.Flush(uicore.layer.menu)
        menu = xtriui.ActionMenu(uicls.Container(name='actionMenu', parent=uicore.layer.menu, state=uiconst.UI_HIDDEN, align=uiconst.TOPLEFT))
        menu.expandTime = blue.os.GetTime()
        menu.Load(slimItem, centerItem)
        if not (eve.triapp.uilib.leftbtn or eve.triapp.uilib.midbtn):
            sm.StartService('state').SetState(slimItem.itemID, state.selected, 1)
            menu.Close()
            return 
        sm.StartService('state').SetState(slimItem.itemID, state.mouseOver, 0)
        menu.state = uix.UI_NORMAL
        uicls.Container(name='blocker', parent=uicore.layer.menu, state=uiconst.UI_NORMAL, align=uiconst.TOALL, pos=(0, 0, 0, 0))
        if (slimItem.itemID == eve.session.shipid):
            displayName = ('%s %s' % (mls.UI_GENERIC_YOUR, cfg.invgroups.Get(slimItem.groupID).name))
        else:
            displayName = uix.GetSlimItemName(slimItem)
            bp = sm.StartService('michelle').GetBallpark()
            if bp:
                ball = bp.GetBall(slimItem.itemID)
                if ball:
                    displayName += (' ' + util.FmtDist(ball.surfaceDist))
        self.AddHint(displayName, menu)



    def AddHint(self, hint, where):
        hintobj = xtriui.SlimDeco(uicls.Container(parent=where, name='hint', align=uiconst.TOPLEFT, width=200, height=16, idx=0, state=uix.UI_DISABLED))
        hintobj.hinttext = uicls.Label(text=hint, parent=hintobj, top=4, letterspace=2, fontsize=9, state=uiconst.UI_DISABLED, uppercase=1)
        hintobj.children.append(blue.os.LoadObject('res:/UI/Component/hint_underlay.blue'))
        if (hintobj.hinttext.textwidth > 200):
            hintobj.hinttext.autowidth = 0
            hintobj.hinttext.width = 200
            hintobj.hinttext.text = (('<center>' + hint) + '</center>')
        hintobj.width = max(56, (hintobj.hinttext.textwidth + 16))
        hintobj.height = max(16, (hintobj.hinttext.textheight + (hintobj.hinttext.top * 2)))
        hintobj.left = ((where.width - hintobj.width) / 2)
        hintobj.top = (-hintobj.height - 4)
        hintobj.hinttext.left = ((hintobj.width - hintobj.hinttext.textwidth) / 2)



    def MapMenu(self, itemIDs, showInactive = 0, unparsed = 0):
        if (type(itemIDs) == list):
            menus = []
            for itemID in itemIDs:
                menus.append(self._MapMenu(itemID, showInactive, unparsed))

            return self.MergeMenus(menus)
        else:
            return self._MapMenu(itemIDs, showInactive, unparsed)



    def _MapMenu(self, itemID, showInactive = 0, unparsed = 0, filterFunc = None):
        mapItem = sm.StartService('map').GetItem(itemID)
        if (mapItem is None):
            return []
        else:
            checkSolarsystem = [(mapItem.typeID == const.typeSolarSystem),
             'This is solarsystem',
             'This is not solarsystem']
            menuEntries = []
            if (checkSolarsystem[0] is True):
                waypoints = sm.StartService('starmap').GetWaypoints()
                (uni, regionID, constellationID, _sol, _item,) = sm.StartService('map').GetParentLocationID(itemID, gethierarchy=1)
                checkInWaypoints = [(itemID in waypoints),
                 'Solarsystem is already waypoint',
                 'Solarsystem is not in waypoints']
                menuEntries += [None,
                 [mls.UI_CMD_SETDESTINATION,
                  sm.StartService('starmap').SetWaypoint,
                  (itemID, 1),
                  (checkSolarsystem, True),
                  mls.UI_CMD_JUMP],
                 [mls.UI_CMD_REMOVEWAYPOINT,
                  sm.StartService('starmap').ClearWaypoints,
                  (itemID),
                  (checkSolarsystem,
                   True,
                   checkInWaypoints,
                   True),
                  mls.UI_CMD_JUMP],
                 [mls.UI_CMD_ADDWAYPOINT,
                  sm.StartService('starmap').SetWaypoint,
                  (itemID),
                  (checkSolarsystem,
                   True,
                   checkInWaypoints,
                   False),
                  mls.UI_CMD_JUMP],
                 [mls.UI_CMD_BOOKMARKLOCATION,
                  self.Bookmark,
                  (itemID,
                   const.typeSolarSystem,
                   constellationID),
                  (checkSolarsystem, True),
                  'bookmark']]
            if unparsed:
                return menuEntries
            return self.ParseMenu(menuEntries, showInactive, filterFunc)



    def InvItemMenu(self, invItems, viewOnly = 0, voucher = None, showInactive = 0, unparsed = 0, filterFunc = None):
        if (type(invItems) == list):
            menus = []
            for (invItem, viewOnly, voucher,) in invItems:
                menus.append(self._InvItemMenu(invItem, viewOnly, voucher, showInactive, unparsed, (len(invItems) > 1), filterFunc, allInvItems=invItems))

            return self.MergeMenus(menus)
        else:
            return self.MergeMenus([self._InvItemMenu(invItems, viewOnly, voucher, showInactive, unparsed, filterFunc=filterFunc, allInvItems=None)])



    def _InvItemMenu(self, invItem, viewOnly, voucher, showInactive = 0, unparsed = 0, multi = 0, filterFunc = None, allInvItems = None):
        if (invItem.groupID == const.groupMoney):
            return []
        else:
            showInactive = (showInactive or settings.user.ui.Get('showInactiveMenus', 0))
            godmaSM = self.godma.GetStateManager()
            invType = cfg.invtypes.Get(invItem.typeID)
            groupID = invType.groupID
            invGroup = cfg.invgroups.Get(groupID)
            groupName = invGroup.name
            categoryID = invGroup.categoryID
            invCategory = cfg.invcategories.Get(categoryID)
            serviceMask = None
            if eve.session.stationid:
                serviceMask = eve.stationItem.serviceMask
            badCateg = (mls.UI_MENUHINT_BADTYPE % invCategory.name)
            badGroup = (mls.UI_MENUHINT_BADTYPE % groupName)
            badType = (mls.UI_MENUHINT_BADTYPE % invType.name)
            checkIfInSpace = self.GetCheckInSpace()
            checkIfInStation = self.GetCheckInStation()
            checkIfDrone = [(categoryID == const.categoryDrone),
             badCateg,
             badCateg]
            checkIfIsPreview = [((categoryID in const.previewCategories) or (groupID in const.previewGroups)),
             'Can be previewed',
             'Cannot be previewed']
            checkIfInDroneBay = [(invItem.flagID == const.flagDroneBay),
             'Drone is in dronebay',
             'Drone is not in dronebay']
            checkIfInHangar = [(invItem.flagID == const.flagHangar),
             mls.UI_MENUHINT_CHECKIFINHANGAR,
             mls.UI_MENUHINT_CHECKIFINHANGARNOT]
            checkIfInCargo = [(invItem.flagID == const.flagCargo),
             'Item is in the cargo',
             'Item is not in the cargo a ship']
            locationItem = ((checkIfInSpace and self.michelle.GetItem(invItem.locationID)) or None)
            checkIfDBLessAmmo = [((type(invItem.itemID) is tuple) and ((locationItem is not None) and (locationItem.categoryID == const.categoryStructure))),
             'DBLess item is in the structure',
             'DBLess item is not in the structure']
            checkIfInShipMA = [((locationItem is not None) and (locationItem.groupID == const.groupShipMaintenanceArray)),
             mls.UI_MENUHINT_CHECKIFINSHIPMA,
             mls.UI_MENUHINT_CHECKIFINSHIPMANOT]
            checkIfInShipMAShip = [((locationItem is not None) and ((locationItem.categoryID == const.categoryShip) and (godmaSM.GetType(locationItem.typeID).hasShipMaintenanceBay and (invItem.flagID == const.flagShipHangar)))),
             'Item is in a ship maintenance array (ship)',
             'Item is not in a ship maintenance array (ship)']
            checkIfInShipMAShip2 = [((locationItem is not None) and ((locationItem.categoryID == const.categoryShip) and (godmaSM.GetType(locationItem.typeID).hasShipMaintenanceBay and ((invItem.flagID == const.flagShipHangar) and (invItem.locationID != eve.session.shipid))))),
             mls.UI_MENUHINT_CHECKIFINSHIPMASHIP2,
             mls.UI_MENUHINT_CHECKIFINSHIPMASHIP2NOT]
            checkIfInCHShip = [((locationItem is not None) and ((locationItem.categoryID == const.categoryShip) and (godmaSM.GetType(locationItem.typeID).hasCorporateHangars and (invItem.flagID in (const.flagHangar,
              const.flagCorpSAG2,
              const.flagCorpSAG3,
              const.flagCorpSAG4,
              const.flagCorpSAG5,
              const.flagCorpSAG6,
              const.flagCorpSAG7))))),
             'Item is in a ship maintenance array (ship)',
             'Item is not in a ship maintenance array (ship)']
            checkIfShipMAShip = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).hasShipMaintenanceBay)),
             'This is a ship maintenance array (ship)',
             'This is not a ship maintenance array (ship)']
            checkIfShipCHShip = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).hasCorporateHangars)),
             'This has corporate hangars (ship)',
             'This does not have corporate hangars (ship)']
            checkMAInRange = [self.CheckMAInRange(const.maxConfigureDistance),
             'You are within maximum configuration distance',
             'You are not within maximum configuration distance']
            checkIfShipFuelBay = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialFuelBayCapacity)),
             'This ship has a specialized fuel bay',
             'This ship does not have a specialized fuel bay']
            checkIfShipOreHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialOreHoldCapacity)),
             'This ship has a specialized ore hold',
             'This ship does not have a specialized ore hold']
            checkIfShipGasHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialGasHoldCapacity)),
             'This ship has a specialized gas hold',
             'This ship does not have a specialized gas hold']
            checkIfShipMineralHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialMineralHoldCapacity)),
             'This ship has a specialized mineral hold',
             'This ship does not have a specialized mineral hold']
            checkIfShipSalvageHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialSalvageHoldCapacity)),
             'This ship has a specialized salvage hold',
             'This ship does not have a specialized salvage hold']
            checkIfShipShipHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialShipHoldCapacity)),
             'This ship has a specialized ship hold',
             'This ship does not have a specialized ship hold']
            checkIfShipSmallShipHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialSmallShipHoldCapacity)),
             'This ship has a specialized small ship hold',
             'This ship does not have a specialized small ship hold']
            checkIfShipMediumShipHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialMediumShipHoldCapacity)),
             'This ship has a specialized medium ship hold',
             'This ship does not have a specialized medium ship hold']
            checkIfShipLargeShipHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialLargeShipHoldCapacity)),
             'This ship has a specialized large ship hold',
             'This ship does not have a specialized large ship hold']
            checkIfShipIndustrialShipHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialIndustrialShipHoldCapacity)),
             'This ship has a specialized industrial ship hold',
             'This ship does not have a specialized industrial ship hold']
            checkIfShipAmmoHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialAmmoHoldCapacity)),
             'This ship has a specialized ammo hold',
             'This ship does not have a specialized ammo hold']
            checkIfShipCommandCenterHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialCommandCenterHoldCapacity)),
             'This ship has a specialized command center hold',
             'This ship does not have a specialized command center hold']
            checkIfShipPlanetaryCommoditiesHold = [((categoryID == const.categoryShip) and bool(godmaSM.GetType(invItem.typeID).specialPlanetaryCommoditiesHoldCapacity)),
             'This ship has a specialized planetary commodities hold',
             'This ship does not have a specialized planetary commodities hold']
            checkViewOnly = [bool(viewOnly),
             '',
             '']
            checkIfAtStation = [util.IsStation(invItem.locationID),
             'Item is at station',
             'Item is not at station']
            checkIfActiveShip = [(invItem.itemID == eve.session.shipid),
             'This is active ship',
             'This is not active ship']
            checkIfInHangarAtStation = [(not (bool(checkIfInHangar[0]) and (invItem.locationID != eve.session.stationid))),
             'Item is in a hangar at current station or not in a hangar at all',
             'This item is in a hangar at another station']
            checkContainer = [(invItem.groupID in (const.groupWreck,
              const.groupCargoContainer,
              const.groupSecureCargoContainer,
              const.groupAuditLogSecureContainer,
              const.groupFreightContainer,
              const.groupMissionContainer)),
             badGroup,
             badGroup]
            checkCanContain = [cfg.IsContainer(invItem),
             'Item is a container',
             'Item is not a container']
            checkSingleton = [bool(invItem.singleton),
             mls.UI_MENUHINT_CHECKSINGLETON,
             mls.UI_MENUHINT_CHECKSINGLETONNOT]
            checkBPSingleton = [(bool(invItem.singleton) and (invItem.categoryID == const.categoryBlueprint)),
             'Item is a blueprint singleton',
             'Item is not a blueprint singleton']
            checkPlasticWrap = [(invItem.typeID == const.typePlasticWrap),
             badType,
             badType]
            checkIsStation = [util.IsStation(invItem.itemID),
             'Item is station',
             'Item is not station']
            checkIfMineOrCorps = [(invItem.ownerID in [eve.session.corpid, eve.session.charid]),
             'Item is owned by you or your corp',
             'Item not is owned by you nor your corp']
            checkIfImInStation = [bool(eve.session.stationid),
             mls.UI_MENUHINT_CHECKIFIMINSTATION,
             mls.UI_MENUHINT_CHECKIFIMINSTATIONNOT]
            checkIfIsMine = [(invItem.ownerID == eve.session.charid),
             'Item is yours',
             'Item is not yours']
            checkIfIsShip = [(invItem.categoryID == const.categoryShip),
             mls.UI_MENUHINT_CHECKSHIP,
             mls.UI_MENUHINT_CHECKSHIPNOT]
            checkIfIsCapsule = [(invItem.groupID == const.groupCapsule),
             'Item is a capsule',
             'Item is not a capsule']
            checkIfIsMyCorps = [(invItem.ownerID == eve.session.corpid),
             'Item is your corps',
             'Item is not your corps']
            checkIfIsStructure = [(invItem.categoryID == const.categoryStructure),
             badCateg,
             badCateg]
            checkIfIsSovStructure = [(categoryID == const.categorySovereigntyStructure),
             'This item is a sovereignty structure',
             'This item is not a sovereignty structure']
            checkIfIsHardware = [invCategory.IsHardware(),
             'This is hardware',
             'This is not hardware']
            checkActiveShip = [bool(eve.session.shipid),
             'You are in ship',
             'You are not in ship']
            checkIfRepackable = [((categoryID in const.repackableCategorys) or (groupID in const.repackableGroups)),
             'This type of item can be repackaged',
             'This type of item cannot be repackaged']
            checkIfNoneLocation = [(invItem.flagID == const.flagNone),
             'This is in no location',
             'This is in a location']
            checkIfAnchorable = [invGroup.anchorable,
             'This item can be anchored',
             'This item cannot be anchored']
            checkConstructionPF = [(groupID in (const.groupConstructionPlatform,
              const.groupStationUpgradePlatform,
              const.groupStationImprovementPlatform)),
             badGroup,
             badGroup]
            checkMineable = [((categoryID == const.categoryAsteroid) or (groupID == const.groupHarvestableCloud)),
             badGroup,
             badGroup]
            checkRefining = [(bool(eve.session.stationid) and bool(((serviceMask & const.stationServiceRefinery) or (serviceMask & const.stationServiceReprocessingPlant)))),
             'Possible to refine',
             'Not possible to refine at this station']
            checkRefinable = [(bool(checkRefining[0]) and sm.StartService('reprocessing').GetOptionsForItemTypes({invItem.typeID: 0})[invItem.typeID].isRefinable),
             'This is refinable ore',
             'This is not refinable ore']
            checkRecyclable = [(bool(checkRefining[0]) and sm.StartService('reprocessing').GetOptionsForItemTypes({invItem.typeID: 0})[invItem.typeID].isRecyclable),
             'This item is reprocessable',
             'This item is not recyclable']
            checkSkill = [(categoryID == const.categorySkill),
             badCateg,
             badCateg]
            checkImplant = [((categoryID == const.categoryImplant) and bool(godmaSM.GetType(invItem.typeID).implantness)),
             badCateg,
             badCateg]
            checkPilotLicence = [(invItem.groupID == const.groupGameTime),
             badType,
             badType]
            checkReverseRedeemable = [(invItem.groupID in const.reverseRedeemingLegalGroups),
             badType,
             badType]
            checkBooster = [((groupID == const.groupBooster) and bool(godmaSM.GetType(invItem.typeID).boosterness)),
             badGroup,
             badGroup]
            checkSecContainer = [(groupID in (const.groupSecureCargoContainer, const.groupAuditLogSecureContainer)),
             badGroup,
             badGroup]
            checkIfInQuickBar = [(invItem.typeID in settings.user.ui.Get('marketquickbar', [])),
             'This type is in quickbar',
             'This type is not in quickbar']
            checkIfSellable = [(util.IsStation(invItem.locationID) and sm.StartService('marketQuote').CanTradeAtStation(0, invItem.locationID)),
             '',
             'Too far away']
            checkMultiSelection = [bool(multi),
             mls.UI_MENUHINT_CHECKMULTISELECTION,
             mls.UI_MENUHINT_CHECKMULTISELECTIONNOT]
            checkAuditLogSecureContainer = [(groupID == const.groupAuditLogSecureContainer),
             'This is an audit log secure container',
             'This is not an audit log secure container']
            checkIfLockedInALSC = [(invItem.flagID == const.flagLocked),
             'Item is locked',
             'Item is not locked']
            checkIfUnlockedInALSC = [(invItem.flagID == const.flagUnlocked),
             'Item is locked',
             'Item is not locked']
            checkSameLocation = self.CheckSameLocation(invItem)
            checkHasMarketGroup = [(cfg.invtypes.Get(invItem.typeID).marketGroupID is not None),
             'Item type has market group',
             'Item type does not have a market group']
            checkIsPublished = [cfg.invtypes.Get(invItem.typeID).published,
             'Item type is published',
             'Item type is not published']
            checkRepairService = [(bool(eve.session.stationid) and bool((serviceMask & const.stationServiceRepairFacilities))),
             'Station has repair service',
             'Not possible to repair at this station']
            checkIfRepairable = [util.IsItemOfRepairableType(invItem),
             'Item type is repairable',
             'Item type if not repairable']
            checkLocationInSpace = [(locationItem is not None),
             'The location of this item is located in space',
             'The location of this item is not located in space']
            checkLocationCorpHangarArrayEquivalent = [((locationItem is not None) and (locationItem.groupID in (const.groupCorporateHangarArray, const.groupAssemblyArray))),
             'This is a corp hangar array equivalent',
             'This is not a corp hangar array equivalent']
            checkShipInStructure = [((locationItem is not None) and ((locationItem.categoryID == const.categoryStructure) and (invItem.categoryID == const.categoryShip))),
             'Is a ship in a starbase structure',
             'Is not a ship or not in a starbase structure']
            checkInControlTower = [((locationItem is not None) and (locationItem.groupID == const.groupControlTower)),
             'Is in a control tower',
             'Is not in a control tower']
            checkIfInHangarOrCorpHangarAndCanTake = self.CheckIfInHangarOrCorpHangarAndCanTake(invItem)
            checkIfInDeliveries = [(invItem.flagID == const.flagCorpMarket),
             'Item is in deliveries',
             'Item is not in deliveries']
            checkIfInHangarOrCorpHangarOrDeliveriesAndCanTake = [(checkIfInHangarOrCorpHangarAndCanTake[0] or checkIfInDeliveries[0]),
             'Can take',
             'Cannot take']
            checkIfRAMCompatible = [sm.StartService('manufacturing').IsRamCompatible(invItem.itemID),
             'Item is compatible for manufacturing',
             'Item is not compatible for manufacturing']
            checkIsRamInstallable = [sm.StartService('manufacturing').IsRamInstallable(invItem),
             'Item is compatible for manufacturing',
             'Item is not compatible for manufacturing']
            checkIsReverseEngineering = [sm.StartService('manufacturing').IsReverseEngineering(invItem),
             'Item is compatible for reverse engineering',
             'Item is not compatible for reverse engineering']
            checkIfLockableBlueprint = self.CheckIfLockableBlueprint(invItem)
            checkIfUnlockableBlueprint = self.CheckIfUnlockableBlueprint(invItem)
            checkIfIAmDirector = [((eve.session.corprole & const.corpRoleDirector) > 0),
             'You are a Director',
             'You are not a Director']
            checkItemIsInSpace = [bool(const.minSolarSystem <= invItem.locationID <= const.maxSolarSystem),
             'Is in space',
             'Is not in space']
            checkStack = [(invItem.stacksize > 1),
             'Is Stack',
             'Is Not Stack']
            checkIfQueueOpen = [sm.StartService('skillqueue').IsQueueWndOpen(),
             'Skill queue wnd is closed',
             'Skill queue wnd is open']
            checkMultStations = [False,
             'Items from multiple stations',
             'Item not from multiple stations']
            if (allInvItems and (len(allInvItems) > 0)):
                checkIsMultipleStations = False
                locationIDCompare = allInvItems[0][0].locationID
                for item in allInvItems:
                    item = item[0]
                    if (item.locationID != locationIDCompare):
                        checkIsMultipleStations = True
                        break

                checkMultStations = [checkIsMultipleStations,
                 'Items from multiple stations',
                 'Item not from multiple stations']
            menuEntries = []
            if checkIfActiveShip:
                menuEntries += self.RigSlotMenu(invItem.itemID)
            menuEntries += [[mls.UI_CMD_SHOWINFO,
              self.ShowInfo,
              (invItem.typeID,
               invItem.itemID,
               0,
               invItem,
               None),
              (checkMultiSelection, False)],
             [mls.UI_CMD_LAUNCHDRONES,
              self.LaunchDrones,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfDrone,
               True,
               checkIfInDroneBay,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_SPLITSTACK,
              self.SplitStack,
              [invItem],
              (checkStack,
               True,
               checkIfInDeliveries,
               False,
               checkIfIsMyCorps,
               True,
               checkIfInHangarOrCorpHangarAndCanTake,
               True)],
             None,
             [mls.UI_CMD_REFINE,
              self.Refine,
              [invItem],
              (checkMineable,
               True,
               checkIfInStation,
               True,
               checkRefining,
               True,
               checkRefinable,
               True,
               checkIfAtStation,
               True,
               checkViewOnly,
               False,
               checkIfInDeliveries,
               False,
               checkIfInHangarAtStation,
               True),
              'reprocessingplant'],
             [mls.UI_CMD_REPROCESS,
              self.Refine,
              [invItem],
              (checkSameLocation,
               True,
               checkIfInStation,
               True,
               checkRefining,
               True,
               checkRecyclable,
               True,
               checkIfAtStation,
               True,
               checkViewOnly,
               False,
               checkIfInDeliveries,
               False,
               checkIfActiveShip,
               False),
              'reprocessingplant'],
             [mls.UI_CMD_TOHANGARANDREFINE,
              self.RefineToHangar,
              [invItem],
              (checkMineable,
               True,
               checkIfInStation,
               True,
               checkRefining,
               True,
               checkIfAtStation,
               False,
               checkViewOnly,
               False,
               checkIfInDeliveries,
               False,
               checkRefinable,
               True)],
             None,
             [(mls.UI_SHARED_SQ_TRAINNOW % {'num': 1}),
              self.TrainNow,
              [invItem],
              (checkSkill,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkIfQueueOpen,
               False)],
             [mls.UI_SHARED_SKILLS_INJECT,
              self.InjectSkillIntoBrain,
              [invItem],
              (checkSkill,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_PLUGIN,
              self.PlugInImplant,
              [invItem],
              (checkImplant,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_APPLYPILOTLICENCE,
              self.ApplyPilotLicence,
              (invItem.itemID),
              (checkPilotLicence,
               True,
               checkViewOnly,
               False,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_REVERSEREDEEM,
              sm.GetService('redeem').ReverseRedeem,
              (invItem),
              (checkReverseRedeemable,
               True,
               checkViewOnly,
               False,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_CONSUME,
              self.ConsumeBooster,
              [invItem],
              (checkBooster,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False)],
             None,
             [mls.UI_CMD_SETNEWPASSWORD,
              self.AskNewContainerPwd,
              ([invItem],
               mls.UI_GENERIC_SETPASSWORDONSECURECONT,
               const.SCCPasswordTypeGeneral),
              (checkSecContainer,
               True,
               checkIfInStation,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_SETNEWCONFIGURATIONPASSWORD,
              self.AskNewContainerPwd,
              ([invItem],
               mls.UI_GENERIC_SETPASSWORDONSECURECONT,
               const.SCCPasswordTypeConfig),
              (checkAuditLogSecureContainer,
               True,
               checkIfInStation,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_VIEWLOG,
              self.ViewAuditLogForALSC,
              (invItem.itemID),
              (checkAuditLogSecureContainer,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkIfMineOrCorps,
               True)],
             [mls.UI_CMD_CONFIGURECONTAINER,
              self.ConfigureALSC,
              (invItem.itemID),
              (checkAuditLogSecureContainer,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkIfMineOrCorps,
               True)],
             [mls.UI_CMD_RETRIEVEPASSWORD,
              self.RetrievePasswordALSC,
              (invItem.itemID),
              (checkAuditLogSecureContainer,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkIfMineOrCorps,
               True)],
             [mls.UI_CMD_SETNAME,
              self.SetName,
              [invItem],
              (checkContainer,
               True,
               checkViewOnly,
               False,
               checkSameLocation,
               True,
               checkSingleton,
               True,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_ASSEMBLECONTAINER,
              self.AssembleContainer,
              [invItem],
              (checkContainer,
               True,
               checkIfInStation,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               False)],
             None,
             [mls.UI_CMD_SETACCESSPASSWORD,
              self.AskNewContainerPwd,
              ([invItem],
               mls.UI_GENERIC_SETACCESSPASSWORDONCONSTRPLATFORM,
               const.SCCPasswordTypeGeneral),
              (checkConstructionPF,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_SETBUILDPASSWORD,
              self.AskNewContainerPwd,
              ([invItem],
               mls.UI_GENERIC_SETBUILDPASSWORDONCONSTRPLATFORM,
               const.SCCPasswordTypeConfig),
              (checkConstructionPF,
               True,
               checkViewOnly,
               False,
               checkSingleton,
               True,
               checkMultiSelection,
               False)],
             [mls.UI_CMD_TRANSFERTOCARGO,
              self.TransferToCargo,
              (invItem.itemID),
              (checkIfInSpace,
               True,
               checkIfDBLessAmmo,
               True,
               checkMultiSelection,
               False)],
             None,
             [mls.UI_CMD_LOCKITEM,
              self.ALSCLock,
              [invItem],
              (checkIfUnlockedInALSC, True)],
             [mls.UI_CMD_UNLOCKITEM,
              self.ALSCUnlock,
              [invItem],
              (checkIfLockedInALSC, True)],
             [mls.UI_CMD_PROPOSE_LOCKDOWN_VOTE,
              self.LockDownBlueprint,
              (invItem),
              (checkIfLockableBlueprint, True)],
             [mls.UI_CMD_PROPOSE_UNLOCK_VOTE,
              self.UnlockBlueprint,
              (invItem),
              (checkIfUnlockableBlueprint, True)],
             [mls.UI_CMD_GETREPAIRQUOTE,
              self.RepairItems,
              [invItem],
              (checkIfInStation,
               True,
               checkRepairService,
               True,
               checkIfRepairable,
               True,
               checkIfAtStation,
               True,
               checkSameLocation,
               True,
               checkIfIsMine,
               True),
              'any'],
             [mls.UI_CMD_VIEWMARKETDETAILS,
              self.ShowMarketDetails,
              (invItem),
              (checkHasMarketGroup,
               True,
               checkMultiSelection,
               False,
               checkIsStation,
               False),
              'market'],
             [mls.UI_CMD_SELLTHISITEM,
              self.QuickSell,
              (invItem),
              (checkHasMarketGroup,
               True,
               checkIsStation,
               False,
               checkIfMineOrCorps,
               True,
               checkIfActiveShip,
               False,
               checkIfInHangarOrCorpHangarAndCanTake,
               True,
               checkMultiSelection,
               False,
               checkBPSingleton,
               False),
              'reprocessingplant'],
             [mls.UI_CMD_BUYTHISTYPE,
              self.QuickBuy,
              (invItem.typeID),
              (checkHasMarketGroup,
               True,
               checkIsStation,
               False,
               checkMultiSelection,
               False),
              'any'],
             [mls.UI_CMD_CONTRACTTHISITEM,
              self.QuickContract,
              [invItem],
              (checkIsStation,
               False,
               checkIfMineOrCorps,
               True,
               checkIfActiveShip,
               False,
               checkMultStations,
               False,
               checkIfInHangarOrCorpHangarOrDeliveriesAndCanTake,
               True),
              'contracts']]
            menuEntries += [[mls.UI_CMD_FINDINCONTRACTS,
              sm.GetService('contracts').FindRelated,
              (invItem.typeID,
               None,
               None,
               None,
               None,
               None),
              (checkIsPublished,
               True,
               checkMultiSelection,
               False,
               checkIsStation,
               False),
              'market']]
            menuEntries += [[mls.UI_CMD_ADDTOMARKETQUICKBAR,
              self.AddToQuickBar,
              (invItem.typeID),
              (checkHasMarketGroup,
               True,
               checkIfInQuickBar,
               False,
               checkMultiSelection,
               False,
               checkIsStation,
               False),
              'any'],
             [mls.UI_CMD_REMOVEFROMMARKETQUICKBAR,
              self.RemoveFromQuickBar,
              (invItem),
              (checkIfInQuickBar,
               True,
               checkMultiSelection,
               False),
              'any'],
             [mls.UI_CMD_VIEWCONTENTS,
              self.GetContainerContents,
              [invItem],
              (checkIfInHangar,
               True,
               checkIfAtStation,
               True,
               checkIfIsMine,
               True,
               checkCanContain,
               True),
              'any']]
            menuEntries += [[mls.UI_CMD_OPENCONTAINER,
              self.OpenContainer,
              [invItem],
              (checkViewOnly,
               False,
               checkContainer,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True)],
             [mls.UI_CMD_BREAK,
              self.Break,
              [invItem],
              (checkViewOnly,
               False,
               checkContainer,
               True,
               checkSingleton,
               True,
               checkIfAtStation,
               True,
               checkIfInHangar,
               True,
               checkPlasticWrap,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_DELIVER,
              self.DeliverCourierContract,
              [invItem],
              (checkViewOnly,
               False,
               checkContainer,
               True,
               checkSingleton,
               True,
               checkIfAtStation,
               True,
               checkIfInHangar,
               True,
               checkPlasticWrap,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_FINDCONTRACT,
              self.FindCourierContract,
              [invItem],
              (checkViewOnly,
               False,
               checkContainer,
               True,
               checkSingleton,
               True,
               checkPlasticWrap,
               True)],
             [mls.UI_CMD_MAKEACTIVE,
              self.ItemLockFunction,
              (invItem,
               mls.UI_GENERIC_ACTIVATED.lower(),
               self.ActivateShip,
               (invItem)),
              (checkIfActiveShip,
               False,
               checkIfIsShip,
               True,
               checkSameLocation,
               True,
               checkIfImInStation,
               True,
               checkIfMineOrCorps,
               True,
               checkIfAtStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsMine,
               True,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkViewOnly,
               False)],
             [mls.UI_CMD_LEAVESHIP,
              self.ItemLockFunction,
              (invItem,
               mls.UI_GENERIC_LEAVINGSHIP.lower(),
               self.LeaveShip,
               (invItem)),
              (checkIfActiveShip,
               True,
               checkIfIsShip,
               True,
               checkSameLocation,
               True,
               checkIfImInStation,
               True,
               checkIfMineOrCorps,
               True,
               checkIfAtStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsMine,
               True,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkViewOnly,
               False,
               checkIfIsCapsule,
               False)],
             [mls.UI_CMD_STRIPFITTING,
              self.StripFitting,
              [invItem],
              (checkIfIsShip,
               True,
               checkSameLocation,
               True,
               checkIfImInStation,
               True,
               checkIfAtStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsMine,
               True,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkViewOnly,
               False,
               checkIfIsCapsule,
               False)],
             None]
            menuEntries += [ [(text, menu.BLUEPRINTGROUP),
             self.Manufacture,
             [invItem, actID],
             (checkIsRamInstallable, True)] for (actID, text,) in sm.GetService('manufacturing').GetActivities() if (actID != const.activityNone) ]
            menuEntries += [ [(text, menu.BLUEPRINTGROUP),
             self.Manufacture,
             [invItem, actID],
             (checkIsReverseEngineering, True)] for (actID, text,) in sm.GetService('manufacturing').GetActivities() if (actID == const.activityReverseEngineering) ]
            menuEntries += [None,
             [mls.UI_CMD_ASSEMBLESHIP,
              self.AssembleShip,
              [invItem],
              (checkIfIsShip,
               True,
               checkSameLocation,
               True,
               checkIfImInStation,
               True,
               checkIfAtStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsMine,
               True,
               checkSingleton,
               False,
               checkViewOnly,
               False)],
             [mls.UI_CMD_ASSEMBLESHIP,
              self.AssembleShip,
              [invItem],
              (checkIfIsShip,
               True,
               checkIfInSpace,
               True,
               checkIfInCargo,
               True,
               checkIfIsMine,
               True,
               checkSingleton,
               False,
               checkViewOnly,
               False)],
             [mls.UI_CMD_ASSEMBLESHIP,
              self.AssembleShip,
              [invItem],
              (checkIfIsShip,
               True,
               checkIfInSpace,
               True,
               checkLocationCorpHangarArrayEquivalent,
               True,
               checkLocationInSpace,
               True,
               checkSingleton,
               False,
               checkViewOnly,
               False)],
             [mls.UI_CMD_FITTOACTIVESHIP,
              self.TryFit,
              [invItem],
              (checkIfImInStation,
               True,
               checkIfIsHardware,
               True,
               checkActiveShip,
               True,
               checkSameLocation,
               True,
               checkViewOnly,
               False,
               checkImplant,
               False,
               checkBooster,
               False)],
             [mls.UI_CMD_MOVETODRONEBAY,
              self.FitDrone,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfInDroneBay,
               False,
               checkIfDrone,
               True,
               checkViewOnly,
               False,
               checkMAInRange,
               True)],
             None,
             [mls.UI_CMD_OPENCARGOHOLD,
              self.OpenCargohold,
              [invItem],
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True),
              'ships'],
             [mls.UI_CMD_OPENSHIPMAINTENANCEBAY,
              self.OpenShipMaintenanceBayShip,
              (invItem.itemID, mls.UI_SHIPMAINTENANCEBAY),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipMAShip,
               True)],
             [mls.UI_CMD_OPENCORPHANGARS,
              self.OpenShipCorpHangars,
              (invItem.itemID, 'Corporate Hangars'),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipCHShip,
               True)],
             [mls.UI_CMD_OPENDRONEBAY,
              self.OpenDroneBay,
              [invItem],
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True),
              'ships'],
             [mls.UI_CMD_OPENFUELBAY,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedFuelBay),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipFuelBay,
               True),
              'Special Fuel Bay'],
             [mls.UI_CMD_OPENOREHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedOreHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipOreHold,
               True),
              'Special Ore Hold'],
             [mls.UI_CMD_OPENGASHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedGasHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipGasHold,
               True),
              'Special Gas Hold'],
             [mls.UI_CMD_OPENMINERALHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedMineralHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipMineralHold,
               True),
              'Special Mineral Hold'],
             [mls.UI_CMD_OPENSALVAGEHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedSalvageHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipSalvageHold,
               True),
              'Special Salvage Hold'],
             [mls.UI_CMD_OPENSHIPHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedShipHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipShipHold,
               True),
              'Special Ship Hold'],
             [mls.UI_CMD_OPENSMALLSHIPHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedSmallShipHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipSmallShipHold,
               True),
              'Special Small Ship Hold'],
             [mls.UI_CMD_OPENMEDIUMSHIPHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedMediumShipHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipMediumShipHold,
               True),
              'Special Medium Ship Hold'],
             [mls.UI_CMD_OPENLARGESHIPHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedLargeShipHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipLargeShipHold,
               True),
              'Special Large Ship Hold'],
             [mls.UI_CMD_OPENINDUSTRIALSHIPHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedIndustrialShipHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipIndustrialShipHold,
               True),
              'Special Industrial Ship Hold'],
             [mls.UI_CMD_OPENAMMOHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedAmmoHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipAmmoHold,
               True),
              'Special Ammo Hold'],
             [mls.UI_CMD_OPENCOMMANDCENTERHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedCommandCenterHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipCommandCenterHold,
               True),
              'Special Command Center Hold'],
             [mls.UI_CMD_OPENPLANETARYCOMMODITIESHOLD,
              self.OpenSpecialCargoBay,
              (invItem.itemID, const.flagSpecializedPlanetaryCommoditiesHold),
              (checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkSingleton,
               True,
               checkSameLocation,
               True,
               checkIfShipPlanetaryCommoditiesHold,
               True),
              'Special Planetary Commodities Hold'],
             None,
             [mls.UI_CMD_CHANGENAME,
              self.ItemLockFunction,
              (invItem,
               mls.UI_GENERIC_RENAMED.lower(),
               self.SetName,
               [[invItem]]),
              (checkSameLocation,
               True,
               checkIfImInStation,
               True,
               checkIfInHangar,
               True,
               checkIfIsShip,
               True,
               checkIfIsMine,
               True,
               checkSingleton,
               True,
               checkMultiSelection,
               False,
               checkViewOnly,
               False),
              'any'],
             [mls.UI_CMD_REPACKAGE,
              self.Repackage,
              [invItem],
              (checkIsStation,
               False,
               checkSingleton,
               True,
               checkIfInHangarOrCorpHangarAndCanTake,
               True,
               checkIfMineOrCorps,
               True,
               checkIfActiveShip,
               False,
               checkIfRepackable,
               True)],
             None,
             [mls.UI_CMD_LAUNCHFORSELF,
              self.LaunchForSelf,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfInCargo,
               True,
               checkIfAnchorable,
               True,
               checkConstructionPF,
               False,
               checkIfIsStructure,
               False,
               checkIfIsSovStructure,
               False,
               checkViewOnly,
               False)],
             [mls.UI_CMD_LAUNCHFORCORP,
              self.LaunchForCorp,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfInCargo,
               True,
               checkIfAnchorable,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_JETTISON,
              self.Jettison,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfInCargo,
               True,
               checkPlasticWrap,
               False,
               checkViewOnly,
               False)],
             [mls.UI_CMD_LAUNCHSHIP,
              self.LaunchSMAContents,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfInShipMA,
               True,
               checkIfIsShip,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_BOARDSHIP,
              self.BoardSMAShip,
              (invItem.locationID, invItem.itemID),
              (checkIfInSpace,
               True,
               checkIfInShipMA,
               True,
               checkIfIsShip,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_LAUNCHSHIPFROMBAY,
              self.LaunchSMAContents,
              [invItem],
              (checkIfInSpace,
               True,
               checkIfInShipMAShip,
               True,
               checkIfIsShip,
               True,
               checkViewOnly,
               False)],
             [mls.UI_CMD_BOARDSHIPFROMBAY,
              self.BoardSMAShip,
              (invItem.locationID, invItem.itemID),
              (checkIfInSpace,
               True,
               checkIfInShipMAShip2,
               True,
               checkIfIsShip,
               True,
               checkViewOnly,
               False)],
             None,
             [mls.UI_CMD_UNDOCKFROMSTATION,
              self.ExitStation,
              (invItem),
              (checkIfImInStation,
               True,
               checkSameLocation,
               True,
               checkIfIsShip,
               True,
               checkIfActiveShip,
               True),
              'undock']]
            if ((not util.IsNPC(eve.session.corpid)) and checkIfIsMyCorps[0]):
                deliverToMenu = []
                if (self.CheckSameLocation(invItem)[0] or 1):
                    divisions = sm.GetService('corp').GetDivisionNames()
                    deliverToCorpHangarMenu = [(divisions[1],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagHangar]]),
                     (divisions[2],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagCorpSAG2]]),
                     (divisions[3],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagCorpSAG3]]),
                     (divisions[4],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagCorpSAG4]]),
                     (divisions[5],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagCorpSAG5]]),
                     (divisions[6],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagCorpSAG6]]),
                     (divisions[7],
                      self.DeliverToCorpHangarFolder,
                      [[invItem, const.flagCorpSAG7]])]
                    deliverToMenu.append([mls.UI_GENERIC_CORPHANGAR,
                     deliverToCorpHangarMenu,
                     None,
                     []])
                    deliverToMenu.append((mls.UI_GENERIC_MEMBER,
                     self.DeliverToCorpMember,
                     [invItem]))
                    menuEntries += [None, [mls.UI_GENERIC_DELIVER_TO,
                      deliverToMenu,
                      None,
                      (checkIfNoneLocation,
                       False,
                       checkLocationCorpHangarArrayEquivalent,
                       False,
                       checkIfInHangarOrCorpHangarOrDeliveriesAndCanTake,
                       True)]]
            menuEntries += [None,
             [mls.UI_CMD_TRASHIT,
              self.TrashInvItems,
              [invItem],
              (checkIfActiveShip,
               False,
               checkIfInHangar,
               True,
               checkIfAtStation,
               True,
               checkIfIsMine,
               True,
               checkPilotLicence,
               False),
              'market'],
             [mls.UI_CMD_TRASHIT,
              self.TrashInvItems,
              [invItem],
              (checkIfActiveShip,
               False,
               checkIfIsMyCorps,
               True,
               checkIfIAmDirector,
               True,
               checkItemIsInSpace,
               False,
               checkShipInStructure,
               False,
               checkPilotLicence,
               False,
               checkInControlTower,
               False,
               checkIfInHangarOrCorpHangarAndCanTake,
               True)]]
            if unparsed:
                return menuEntries
            m = []
            if ((not (filterFunc and (mls.UI_CMD_GMEXTRAS in filterFunc))) and (eve.session.role & (service.ROLE_GML | service.ROLE_WORLDMOD))):
                m = [(mls.UI_CMD_GMEXTRAS, ('isDynamic',
                   self.GetGMMenu,
                   (invItem.itemID,
                    None,
                    None,
                    invItem,
                    None)))]
            return (m + self.ParseMenu(menuEntries, showInactive, filterFunc))



    def CheckItemsInSamePlace(self, invItems):
        if (len(invItems) == 0):
            return 
        locationID = invItems[0].locationID
        flag = invItems[0].flagID
        ownerID = invItems[0].ownerID
        for item in invItems:
            if ((item.locationID != locationID) or ((item.flagID != flag) or (item.ownerID != ownerID))):
                raise UserError('ItemsMustBeInSameHangar')
            locationID = item.locationID
            ownerID = item.ownerID
            flag = item.flagID
            locationID = item.locationID




    def InvalidateItemLocation(self, ownerID, stationID, flag):
        if (ownerID == eve.session.corpid):
            which = 'offices'
            if (flag == const.flagCorpMarket):
                which = 'deliveries'
            sm.services['objectCaching'].InvalidateCachedMethodCall('corpmgr', 'GetAssetInventoryForLocation', session.corpid, stationID, which)
        else:
            sm.services['objectCaching'].InvalidateCachedMethodCall('stationSvc', 'GetStation', stationID)
            eve.GetInventory(const.containerGlobal).InvalidateStationItemsCache(stationID)



    def DeliverToCorpHangarFolder(self, invItemAndFlagList):
        if (len(invItemAndFlagList) == 0):
            return 
        invItems = []
        itemIDs = []
        for item in invItemAndFlagList:
            invItems.append(item[0])
            itemIDs.append(item[0].itemID)

        self.CheckItemsInSamePlace(invItems)
        fromID = invItems[0].locationID
        doSplit = bool((eve.triapp.uilib.Key(uix.VK_SHIFT) and ((len(invItemAndFlagList) == 1) and (invItemAndFlagList[0][0].stacksize > 1))))
        qty = None
        if doSplit:
            (invItem, flag,) = invItemAndFlagList[0]
            ret = uix.QtyPopup(invItem.stacksize, 1, 1, None, mls.UI_GENERIC_DIVIDESTACK)
            if (ret is not None):
                qty = ret['qty']
        id = sm.StartService('invCache').GetStationIDOfItem(invItems[0])
        stationID = id
        if (stationID is None):
            raise UserError('CanOnlyDoInStations')
        ownerID = invItems[0].ownerID
        flag = invItems[0].flagID
        deliverToFlag = invItemAndFlagList[0][1]
        qty = None
        if doSplit:
            invItem = invItems[0]
            ret = uix.QtyPopup(invItem.stacksize, 1, 1, None, mls.UI_GENERIC_DIVIDESTACK)
            if (ret is not None):
                qty = ret['qty']
        eve.inventorymgr.DeliverToCorpHangar(fromID, stationID, itemIDs, qty, ownerID, deliverToFlag)
        self.InvalidateItemLocation(ownerID, stationID, flag)
        if (ownerID == eve.session.corpid):
            sm.ScatterEvent('OnCorpAssetChange', invItems, stationID)



    def DeliverToCorpMember(self, invItems):
        if (len(invItems) == 0):
            return 
        self.CheckItemsInSamePlace(invItems)
        corpMemberIDs = sm.GetService('corp').GetMemberIDs()
        cfg.eveowners.Prime(corpMemberIDs)
        memberslist = []
        for memberID in corpMemberIDs:
            who = cfg.eveowners.Get(memberID)
            memberslist.append([who.ownerName,
             memberID,
             who.typeID])

        doSplit = (eve.triapp.uilib.Key(uix.VK_SHIFT) and ((len(invItems) == 1) and (invItems[0].stacksize > 1)))
        stationID = sm.StartService('invCache').GetStationIDOfItem(invItems[0])
        if (stationID is None):
            raise UserError('CanOnlyDoInStations')
        ownerID = invItems[0].ownerID
        flag = invItems[0].flagID
        itemIDs = [ item.itemID for item in invItems ]
        res = uix.ListWnd(memberslist, 'character', mls.UI_CORP_SELECTMEMBER, mls.UI_CORP_SELECT_MEMBER_TO_DELIVER_TO, 1)
        if res:
            corporationMemberID = res[1]
            qty = None
            if doSplit:
                invItem = invItems[0]
                ret = uix.QtyPopup(invItem.stacksize, 1, 1, None, mls.UI_GENERIC_DIVIDESTACK)
                if (ret is not None):
                    qty = ret['qty']
            eve.inventorymgr.DeliverToCorpMember(corporationMemberID, stationID, itemIDs, qty, ownerID)
            self.InvalidateItemLocation(ownerID, stationID, flag)
            if (ownerID == eve.session.corpid):
                sm.ScatterEvent('OnCorpAssetChange', invItems, stationID)



    def SplitStack(self, invItems):
        if (len(invItems) != 1):
            raise UserError('CannotPerformOnMultipleItems')
        invItem = invItems[0]
        ret = uix.QtyPopup(invItem.stacksize, 1, 1, None, mls.UI_GENERIC_DIVIDESTACK)
        if (ret is not None):
            qty = ret['qty']
            stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
            if (stationID is None):
                raise UserError('CanOnlyDoInStations')
            flag = invItem.flagID
            eve.inventorymgr.SplitStack(stationID, invItem.itemID, qty, invItem.ownerID)
            self.InvalidateItemLocation(invItem.ownerID, stationID, flag)
            if (invItem.ownerID == eve.session.corpid):
                invItem.quantity = (invItem.quantity - qty)
                sm.ScatterEvent('OnCorpAssetChange', [invItem], stationID)



    def GetDroneMenu(self, data):
        menu = self.DroneMenu(data, unmerged=0)
        return menu



    def DroneMenu(self, data, showInactive = 0, unmerged = 0):
        menu = self.GetGroupSpecificDroneMenu(data, showInactive=showInactive, unmerged=unmerged)
        menu += self.GetCommonDroneMenu(data, showInactive=showInactive, unmerged=unmerged)
        return menu



    def GetGroupSpecificDroneMenu(self, data, showInactive = 0, unmerged = 0):
        menuEntries = []
        for (droneID, groupID, ownerID,) in data:
            droneState = sm.StartService('michelle').GetDroneState(droneID)
            if droneState:
                ownerID = droneState.ownerID
                controllerID = droneState.controllerID
                groupID = cfg.invtypes.Get(droneState.typeID).groupID
            else:
                controllerID = None
            groupName = cfg.invgroups.Get(groupID).name
            bp = sm.StartService('michelle').GetBallpark()
            if not bp:
                return []
            droneBall = bp.GetBall(droneID)
            checkMiningDrone = [(groupID == const.groupMiningDrone),
             ('%s %s' % (mls.UI_MENUHINT_THISIS, groupName)),
             ('%s %s' % (mls.UI_MENUHINT_THISISNOT, groupName))]
            checkFighterDrone = [(groupID == const.groupFighterDrone),
             ('%s %s' % (mls.UI_MENUHINT_THISIS, groupName)),
             ('%s %s' % (mls.UI_MENUHINT_THISISNOT, groupName))]
            checkCombatDrone = [(groupID == const.groupCombatDrone),
             ('%s %s' % (mls.UI_MENUHINT_THISIS, groupName)),
             ('%s %s' % (mls.UI_MENUHINT_THISISNOT, groupName))]
            checkUnanchoringDrone = [(groupID == const.groupUnanchoringDrone),
             ('%s %s' % (mls.UI_MENUHINT_THISIS, groupName)),
             ('%s %s' % (mls.UI_MENUHINT_THISISNOT, groupName))]
            checkOtherDrone = [(not (checkMiningDrone[0] or checkUnanchoringDrone[0])),
             ('%s %s' % (mls.UI_MENUHINT_THISIS, groupName)),
             ('%s %s' % (mls.UI_MENUHINT_THISISNOT, groupName))]
            checkOwner = [(ownerID == eve.session.charid),
             mls.UI_MENUHINT_OWNDRONE,
             mls.UI_MENUHINT_DONTOWNDRONE]
            checkController = [(controllerID == eve.session.shipid),
             mls.UI_MENUHINT_CONTROLDRONE,
             mls.UI_MENUHINT_DONTCONTROLDRONE]
            checkDroneState = [(droneState is not None),
             mls.UI_MENUHINT_CHECKDRONE,
             mls.UI_MENUHINT_CHECKDRONENOT]
            checkFleet = [bool(eve.session.fleetid),
             mls.UI_MENUHINT_INFLEET,
             mls.UI_MENUHINT_NOTINFLEET]
            m = [[mls.UI_CMD_ENGAGETARGET,
              self.EngageTarget,
              [droneID],
              (checkController,
               True,
               checkOtherDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_MINE,
              self.Mine,
              [droneID],
              (checkController,
               True,
               checkMiningDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_MINEREPEATEDLY,
              self.MineRepeatedly,
              [droneID],
              (checkController,
               True,
               checkMiningDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_DELEGATECONTROL,
              ('isDynamic',
               self.GetFleetMemberMenu,
               (self.DelegateControl)),
              [droneID],
              (checkOwner,
               True,
               checkController,
               True,
               checkFleet,
               True,
               checkFighterDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_ASSIST,
              ('isDynamic',
               self.GetFleetMemberMenu,
               (self.Assist)),
              [droneID],
              (checkOwner,
               True,
               checkController,
               True,
               checkFleet,
               True,
               checkCombatDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_GUARD,
              ('isDynamic',
               self.GetFleetMemberMenu,
               (self.Guard)),
              [droneID],
              (checkOwner,
               True,
               checkController,
               True,
               checkFleet,
               True,
               checkCombatDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_RETURNCONTROL,
              self.ReturnControl,
              [droneID],
              (checkOwner,
               False,
               checkController,
               True,
               checkFighterDrone,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_UNANCHOR,
              self.DroneUnanchor,
              [droneID],
              (checkController,
               True,
               checkUnanchoringDrone,
               True,
               checkDroneState,
               True)]]
            if unmerged:
                menuEntries.append(m)
            else:
                menuEntries.append(self.ParseMenu(m, showInactive))

        if unmerged:
            return menuEntries
        else:
            merged = self.MergeMenus(menuEntries)
            return merged



    def GetCommonDroneMenu(self, data, showInactive = 0, unmerged = 0):
        menuEntries = []
        for (droneID, groupID, ownerID,) in data:
            droneState = sm.StartService('michelle').GetDroneState(droneID)
            if droneState:
                ownerID = droneState.ownerID
                controllerID = droneState.controllerID
                groupID = cfg.invtypes.Get(droneState.typeID).groupID
            else:
                controllerID = None
            groupName = cfg.invgroups.Get(groupID).name
            bp = sm.StartService('michelle').GetBallpark()
            if not bp:
                return []
            droneBall = bp.GetBall(droneID)
            checkOwner = [(ownerID == eve.session.charid),
             mls.UI_MENUHINT_OWNDRONE,
             mls.UI_MENUHINT_DONTOWNDRONE]
            checkController = [(controllerID == eve.session.shipid),
             mls.UI_MENUHINT_CONTROLDRONE,
             mls.UI_MENUHINT_DONTCONTROLDRONE]
            checkDroneState = [(droneState is not None),
             mls.UI_MENUHINT_CHECKDRONE,
             mls.UI_MENUHINT_CHECKDRONENOT]
            dist = (droneBall and max(0, droneBall.surfaceDist))
            checkScoopable = [((droneState is None) or (ownerID == eve.session.charid)),
             mls.UI_MENUHINT_CHECKSCOOPABLE,
             mls.UI_MENUHINT_CHECKSCOOPABLENOT]
            checkScoopDist = [((dist is not None) and (dist < const.maxCargoContainerTransferDistance)),
             mls.UI_MENUHINT_CHECKSCOOPDIST,
             mls.UI_MENUHINT_CHECKSCOOPDISTNOT]
            checkFleet = [bool(eve.session.fleetid),
             mls.UI_MENUHINT_INFLEET,
             mls.UI_MENUHINT_NOTINFLEET]
            checkOwnerOrController = [(checkOwner[0] or checkController[0]),
             mls.UI_MENUHINT_CONTROLDRONE,
             mls.UI_MENUHINT_DONTCONTROLDRONE]
            m = [[mls.UI_CMD_RETURNANDORBIT,
              self.ReturnAndOrbit,
              [droneID],
              (checkOwnerOrController,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_RETURNTODRONEBAY,
              self.ReturnToDroneBay,
              [droneID],
              (checkOwner,
               True,
               checkDroneState,
               True)],
             [mls.UI_CMD_SCOOPTODRONEBAY,
              self.ScoopToDroneBay,
              [droneID],
              (checkScoopable,
               True,
               checkScoopDist,
               True)],
             None,
             [mls.UI_CMD_ABANDONDRONE,
              self.AbandonDrone,
              [droneID],
              (checkOwner,
               True,
               checkDroneState,
               True)]]
            if unmerged:
                menuEntries.append(m)
            else:
                menuEntries.append(self.ParseMenu(m, showInactive))

        if unmerged:
            return menuEntries
        else:
            merged = self.MergeMenus(menuEntries)
            return merged



    def CharacterMenu(self, charid, charIDs = [], corpid = None, showInactive = 0, unparsed = 0, filterFunc = None):
        if (type(charid) == list):
            menus = []
            for (chid, coid,) in charid:
                menus.append(self._CharacterMenu(chid, coid, showInactive, unparsed, filterFunc, (len(charid) > 1)))

            return self.MergeMenus(menus)
        else:
            return self._CharacterMenu(charid, corpid, showInactive, unparsed, filterFunc)



    def _CharacterMenu(self, charid, corpid, showInactive = 0, unparsed = 0, filterFunc = None, multi = 0):
        if not charid:
            return []
        else:
            addressBookSvc = sm.GetService('addressbook')
            char = cfg.eveowners.Get(charid)
            checkIsNPC = [util.IsNPC(charid),
             'Character is NPC',
             'Character is not NPC']
            checkIsAgent = [sm.GetService('agents').IsAgent(charid),
             'Character is agent',
             'Character is not agent']
            checkInStation = [(not (not eve.session.stationid)),
             'You are in station',
             'You are not in station']
            checkInAddressbook = [(not (not addressBookSvc.IsInAddressBook(charid, 'contact'))),
             'Character is in your addressbook',
             'Character is not in your addressbook']
            checkInCorpAddressbook = [(not (not addressBookSvc.IsInAddressBook(charid, 'corpcontact'))),
             'Character is in your corp addressbook',
             'Character is not in your corp addressbook']
            checkInAllianceAddressbook = [(not (not addressBookSvc.IsInAddressBook(charid, 'alliancecontact'))),
             'Character is in your alliance addressbook',
             'Character is not in your alliance addressbook']
            checkIfBlocked = [addressBookSvc.IsBlocked(charid),
             'Character is blocked',
             'Character is not blocked']
            checkIfGuest = [(eve.session.stationid and sm.StartService('station').IsGuest(charid)),
             'at station',
             'not at station']
            checkIfMe = [(charid == eve.session.charid),
             mls.UI_MENUHINT_CHECKIFME,
             mls.UI_MENUHINT_CHECKIFMENOT]
            checkHaveCloneBay = [sm.StartService('clonejump').HasCloneReceivingBay(),
             'Your ship has a Clone Receiving Bay',
             'Your ship does not have a Clone Receiving Bay']
            checkBountyOffice = self.CheckBountyOffice()
            checkIAmDirector = [((const.corpRoleDirector & eve.session.corprole) == const.corpRoleDirector),
             "You're a Director",
             "You're not a Director"]
            checkIfExecCorp = [(session.allianceid and (sm.GetService('alliance').GetAlliance(session.allianceid).executorCorpID == session.corpid)),
             'Your corp is exec corp',
             'Your corp is not exec corp']
            checkIAmDiplomat = [(((const.corpRoleDirector | const.corpRoleDiplomat) & session.corprole) != 0),
             "You're a Diplomat",
             "You're not a Diplomat"]
            checkMultiSelection = [bool(multi),
             mls.UI_MENUHINT_CHECKMULTISELECTION,
             mls.UI_MENUHINT_CHECKMULTISELECTIONNOT]
            menuEntries = [[mls.UI_CMD_STARTCONVERSATION,
              sm.StartService('LSC').Invite,
              (charid),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIsNPC,
               False)],
             [(mls.UI_CMD_STARTCONVERSATION, menu.ACTIONSGROUP2),
              sm.StartService('agents').InteractWith,
              (charid),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIsNPC,
               True,
               checkIsAgent,
               True)],
             [mls.UI_CMD_INVITETO,
              ('isDynamic',
               self._MenuSvc__GetInviteMenu,
               (charid)),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIsNPC,
               False)],
             [mls.UI_CMD_SENDMESSAGE,
              sm.StartService('mailSvc').SendMsgDlg,
              ([charid],
               None,
               None),
              (checkIfMe,
               False,
               checkIsNPC,
               False)],
             [mls.UI_CONTACTS_ADDTOCONTACTS,
              addressBookSvc.AddToPersonalMulti,
              [charid, 'contact'],
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkInAddressbook,
               False,
               checkIsNPC,
               False)],
             [mls.UI_CMD_ADDTOADDRESSBOOK,
              addressBookSvc.AddToPersonalMulti,
              [charid],
              (checkIfMe,
               False,
               checkInAddressbook,
               False,
               checkIsNPC,
               True,
               checkIsAgent,
               True)],
             [mls.UI_CONTACTS_EDITCONTACT,
              addressBookSvc.AddToPersonalMulti,
              [charid,
               'contact',
               True],
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkInAddressbook,
               True,
               checkIsNPC,
               False)],
             [mls.UI_CONTACTS_REMOVEFROMCONTACTS,
              addressBookSvc.DeleteEntryMulti,
              [[charid], 'contact'],
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkInAddressbook,
               True,
               checkIsNPC,
               False)],
             [mls.UI_CMD_REMOVEFROMADDRESSBOOK,
              addressBookSvc.DeleteEntryMulti,
              [charid],
              (checkIfMe,
               False,
               checkInAddressbook,
               True,
               checkIsNPC,
               True,
               checkIsAgent,
               True)],
             [mls.UI_CMD_UNBLOCK,
              addressBookSvc.UnblockOwner,
              ([charid]),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIfBlocked,
               True)],
             [mls.UI_CMD_BLOCK,
              addressBookSvc.BlockOwner,
              (charid),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIsNPC,
               False,
               checkIfBlocked,
               False)],
             [mls.UI_CONTACTS_ADDCORPCONTACT,
              addressBookSvc.AddToPersonalMulti,
              [charid, 'corpcontact'],
              (checkInCorpAddressbook,
               False,
               checkIsNPC,
               False,
               checkIAmDiplomat,
               True)],
             [mls.UI_CONTACTS_EDITCORPCONTACT,
              addressBookSvc.AddToPersonalMulti,
              [charid,
               'corpcontact',
               True],
              (checkInCorpAddressbook,
               True,
               checkIsNPC,
               False,
               checkIAmDiplomat,
               True)],
             [mls.UI_CONTACTS_REMOVECORPCONTACT,
              addressBookSvc.DeleteEntryMulti,
              [[charid], 'corpcontact'],
              (checkInCorpAddressbook,
               True,
               checkIsNPC,
               False,
               checkIAmDiplomat,
               True)],
             [mls.UI_CONTACTS_ADDALLIANCECONTACT,
              addressBookSvc.AddToPersonalMulti,
              [charid, 'alliancecontact'],
              (checkInAllianceAddressbook,
               False,
               checkIsNPC,
               False,
               checkIAmDiplomat,
               True,
               checkIfExecCorp,
               True)],
             [mls.UI_CONTACTS_EDITALLIANCECONTACT,
              addressBookSvc.AddToPersonalMulti,
              [charid,
               'alliancecontact',
               True],
              (checkInAllianceAddressbook,
               True,
               checkIsNPC,
               False,
               checkIAmDiplomat,
               True,
               checkIfExecCorp,
               True)],
             [mls.UI_CONTACTS_REMOVEALLIANCECONTACT,
              addressBookSvc.DeleteEntryMulti,
              [[charid], 'alliancecontact'],
              (checkInAllianceAddressbook,
               True,
               checkIsNPC,
               False,
               checkIAmDiplomat,
               True,
               checkIfExecCorp,
               True)],
             [mls.UI_CMD_GIVEMONEY,
              sm.StartService('wallet').TransferMoney,
              (eve.session.charid,
               None,
               charid,
               None),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIsNPC,
               False)],
             [mls.UI_CMD_OFFERCLONEINSTALLATION,
              sm.StartService('clonejump').OfferShipCloneInstallation,
              (charid),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkIsNPC,
               False,
               checkHaveCloneBay,
               True)]]
            if not multi:
                agentInfo = sm.StartService('agents').GetAgentByID(charid)
                if agentInfo:
                    if (agentInfo.solarsystemID and (agentInfo.solarsystemID != eve.session.solarsystemid2)):
                        menuEntries += ([None] + self.MapMenu(agentInfo.solarsystemID, showInactive=showInactive, unparsed=1))
            menuEntries += [[mls.UI_CMD_TRADE,
              sm.StartService('pvptrade').StartTradeSession,
              (charid),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkInStation,
               True,
               checkIsNPC,
               False,
               checkIfGuest,
               True)], [mls.UI_CMD_CAPTUREPORTRAIT,
              sm.StartService('photo').SavePortraits,
              [charid],
              (checkIsNPC, False),
              'any']]
            menuEntries += [[mls.UI_CMD_ADDBOUNTY,
              uicore.cmd.OpenMissions,
              (charid),
              (checkMultiSelection,
               False,
               checkIfMe,
               False,
               checkInStation,
               True,
               checkIsNPC,
               False,
               checkBountyOffice,
               True)]]
            if not checkIsNPC[0]:
                if (eve.session.fleetid is not None):
                    fleetSvc = sm.GetService('fleet')
                    wings = fleetSvc.GetWings()
                    members = fleetSvc.GetMembers()
                    me = members[session.charid]
                    checkIfImLeader = [self.ImFleetLeaderOrCommander(),
                     'You are fleet leader',
                     'You are not fleet leader']
                    member = members.get(charid, None)
                    if (member is None):
                        menuEntries += [[mls.UI_FLEET_INVITETOFLEET,
                          self.FleetInviteMenu(charid),
                          None,
                          (checkMultiSelection,
                           False,
                           checkIfImLeader,
                           True)]]
                    else:
                        menuEntries += [[mls.UI_FLEET_FLEET,
                          ('isDynamic',
                           self.FleetMenu,
                           (charid, False)),
                          (checkMultiSelection, False)]]
                else:
                    menuEntries += [[mls.UI_CMD_FORMFLEETWITH,
                      self.InviteToFleet,
                      [charid],
                      (),
                      'any']]
                menuEntries += self.CorpMemberMenu(charid, multi)
            if unparsed:
                return menuEntries
            m = []
            if ((not (filterFunc and (mls.UI_CMD_GMEXTRAS in filterFunc))) and (eve.session.role & ((service.ROLE_GML | service.ROLE_WORLDMOD) | service.ROLE_LEGIONEER))):
                m = [(mls.UI_CMD_GMEXTRAS, ('isDynamic',
                   self.GetGMMenu,
                   (None,
                    None,
                    charid,
                    None,
                    None)))]
            return (m + self.ParseMenu(menuEntries, showInactive, filterFunc))



    def CheckBountyOffice(self):
        isBountyOffice = False
        if eve.session.stationid:
            services = sm.GetService('station').GetStationServiceInfo()
            serviceMask = eve.stationItem.serviceMask
            for (serviceID, cmdStr, displayName, iconpath, stationOnly, stationServiceIDs,) in services:
                if (serviceID == 'missions'):
                    for bit in stationServiceIDs:
                        if (bit & serviceMask):
                            isBountyOffice = True
                            break


        return [isBountyOffice,
         'Has bounty office',
         'No bounty office']



    def GetCheckInSpace(self):
        return [(not (not eve.session.solarsystemid)),
         mls.UI_MENUHINT_CHECKIFINSPACE,
         mls.UI_MENUHINT_CHECKIFINSPACENOT]



    def GetCheckInStation(self):
        return [(not (not eve.session.stationid)),
         'You are in station',
         'You are not in station']



    def CheckIfLockableBlueprint(self, invItem):
        isLockable = False
        if (invItem.categoryID == const.categoryBlueprint):
            if invItem.singleton:
                if (invItem.ownerID == eve.session.corpid):
                    if ((eve.session.corprole & const.corpRoleDirector) == const.corpRoleDirector):
                        if (invItem.flagID in [const.flagHangar,
                         const.flagCorpSAG2,
                         const.flagCorpSAG3,
                         const.flagCorpSAG4,
                         const.flagCorpSAG5,
                         const.flagCorpSAG6,
                         const.flagCorpSAG7]):
                            rows = sm.StartService('corp').GetMyCorporationsOffices().SelectByUniqueColumnValues('officeID', [invItem.locationID])
                            if (rows and (len(rows) and (rows[0].officeID == invItem.locationID))):
                                if not sm.GetService('corp').IsItemLocked(invItem):
                                    isLockable = True
        return [(not (not isLockable)),
         'Can lock blueprint',
         'Can NOT lock blueprint']



    def CheckIfUnlockableBlueprint(self, invItem):
        isUnlockable = False
        if (invItem.categoryID == const.categoryBlueprint):
            if invItem.singleton:
                if (invItem.ownerID == eve.session.corpid):
                    if ((eve.session.corprole & const.corpRoleDirector) == const.corpRoleDirector):
                        if (invItem.flagID in [const.flagHangar,
                         const.flagCorpSAG2,
                         const.flagCorpSAG3,
                         const.flagCorpSAG4,
                         const.flagCorpSAG5,
                         const.flagCorpSAG6,
                         const.flagCorpSAG7]):
                            rows = sm.StartService('corp').GetMyCorporationsOffices().SelectByUniqueColumnValues('officeID', [invItem.locationID])
                            if (rows and (len(rows) and (rows[0].officeID == invItem.locationID))):
                                if sm.GetService('corp').IsItemLocked(invItem):
                                    isUnlockable = True
        return [(not (not isUnlockable)),
         'Can unlock blueprint',
         'Can NOT unlock blueprint']



    def CheckIfInHangarOrCorpHangarAndCanTake(self, invItem):
        canTake = False
        corpMember = False
        stationID = None
        bp = sm.StartService('michelle').GetBallpark()
        if (invItem.ownerID == eve.session.charid):
            if (util.IsStation(invItem.locationID) and (invItem.flagID == const.flagHangar)):
                canTake = True
        elif (eve.session.solarsystemid and ((bp is not None) and ((invItem.locationID in bp.slimItems) and (invItem.ownerID == bp.slimItems[invItem.locationID].ownerID)))):
            corpMember = True
        elif ((invItem.ownerID == eve.session.corpid) and (not util.IsNPC(invItem.ownerID))):
            stationID = None
            officeID = None
            rows = sm.StartService('corp').GetMyCorporationsOffices().SelectByUniqueColumnValues('officeID', [invItem.locationID])
            if (rows and len(rows)):
                for row in rows:
                    if (invItem.locationID == row.officeID):
                        officeID = row.officeID
                        stationID = row.stationID
                        break

        if ((stationID is not None) or corpMember):
            flags = [const.flagHangar,
             const.flagCorpSAG2,
             const.flagCorpSAG3,
             const.flagCorpSAG4,
             const.flagCorpSAG5,
             const.flagCorpSAG6,
             const.flagCorpSAG7]
            if (invItem.flagID in flags):
                roles = 0
                if (stationID == eve.session.hqID):
                    roles = eve.session.rolesAtHQ
                elif (stationID == eve.session.baseID):
                    roles = eve.session.rolesAtBase
                else:
                    roles = eve.session.rolesAtOther
                if ((invItem.ownerID == eve.session.corpid) or corpMember):
                    rolesByFlag = {const.flagHangar: const.corpRoleHangarCanTake1,
                     const.flagCorpSAG2: const.corpRoleHangarCanTake2,
                     const.flagCorpSAG3: const.corpRoleHangarCanTake3,
                     const.flagCorpSAG4: const.corpRoleHangarCanTake4,
                     const.flagCorpSAG5: const.corpRoleHangarCanTake5,
                     const.flagCorpSAG6: const.corpRoleHangarCanTake6,
                     const.flagCorpSAG7: const.corpRoleHangarCanTake7}
                    roleRequired = rolesByFlag[invItem.flagID]
                    if ((roleRequired & roles) == roleRequired):
                        canTake = True
        return [(not (not canTake)),
         'Can take from hangar(player/corp)',
         'Can NOT take from hangar(player/corp)']



    def CheckSameLocation(self, invItem):
        inSameLocation = 0
        if eve.session.stationid:
            if (invItem.locationID == eve.session.stationid):
                inSameLocation = 1
            elif util.IsPlayerItem(invItem.locationID):
                inSameLocation = 1
            else:
                office = sm.StartService('corp').GetOffice_NoWireTrip()
                if (office is not None):
                    if (invItem.locationID == office.itemID):
                        inSameLocation = 1
        if ((invItem.locationID == eve.session.shipid) and (invItem.flagID != const.flagShipHangar)):
            inSameLocation = 1
        elif (eve.session.solarsystemid and (invItem.locationID == eve.session.solarsystemid)):
            inSameLocation = 1
        return [inSameLocation,
         mls.UI_MENUHINT_CHECKSAMELOCATION,
         mls.UI_MENUHINT_CHECKSAMELOCATIONNOT]



    def CheckMAInRange(self, useRange):
        if not eve.session.solarsystemid:
            return False
        else:
            bp = sm.StartService('michelle').GetBallpark()
            if not bp:
                return False
            godmaSM = self.godma.GetStateManager()
            for slimItem in bp.slimItems.itervalues():
                if ((slimItem.groupID == const.groupShipMaintenanceArray) or ((slimItem.categoryID == const.categoryShip) and godmaSM.GetType(slimItem.typeID).hasShipMaintenanceBay)):
                    otherBall = bp.GetBall(slimItem.itemID)
                    if otherBall:
                        if (otherBall.surfaceDist < useRange):
                            return True

            return False



    def ImFleetLeaderOrCommander(self):
        return (sm.GetService('fleet').IsBoss() or (eve.session.fleetrole in (const.fleetRoleLeader,
         const.fleetRoleWingCmdr,
         const.fleetRoleSquadCmdr)))



    def ImFleetCommander(self):
        return (eve.session.fleetrole in (const.fleetRoleLeader,
         const.fleetRoleWingCmdr,
         const.fleetRoleSquadCmdr))



    def CheckImFleetLeaderOrBoss(self):
        return [(sm.GetService('fleet').IsBoss() or (eve.session.fleetrole == const.fleetRoleLeader)),
         'You are the fleet leader or commander',
         'You are not the fleet leader or commander']



    def CheckImFleetLeader(self):
        return [(eve.session.fleetrole == const.fleetRoleLeader),
         'You are the fleet leader',
         'You are not the fleet leader']



    def CheckImWingCmdr(self):
        return [(eve.session.fleetrole == const.fleetRoleWingCmdr),
         'You are the wing commander',
         'You are not the wing commander']



    def CheckImSquadCmdr(self):
        return [(eve.session.fleetrole == const.fleetRoleSquadCmdr),
         'You are the squad commander',
         'You are not the squad commander']



    def FleetMenu(self, charID, unparsed = True):

        def ParsedMaybe(menuEntries):
            if unparsed:
                return menuEntries
            else:
                return self.ParseMenu(menuEntries, False, None)


        if (eve.session.fleetid is None):
            return []
        else:
            fleetSvc = sm.GetService('fleet')
            vivox = sm.GetService('vivox')
            wings = fleetSvc.GetWings()
            members = fleetSvc.GetMembers()
            shipItem = util.SlimItemFromCharID(charID)
            bp = sm.StartService('michelle').GetBallpark()
            otherBall = ((bp and (shipItem and bp.GetBall(shipItem.itemID))) or None)
            me = members[session.charid]
            checkIfImLeader = [self.ImFleetLeaderOrCommander(),
             'You are fleet commander',
             'You are not fleet commander']
            checkIfImWingCommanderOrHigher = [(self.CheckImFleetLeaderOrBoss()[0] or self.CheckImWingCmdr()[0]),
             'You are Wing Commander',
             'You are not Wing Commander']
            member = members.get(charID)
            char = cfg.eveowners.Get(charID)
            if (member is None):
                return [[mls.UI_CMD_SHOWINFO,
                  self.ShowInfo,
                  (int(char.Type()),
                   charID,
                   0,
                   None,
                   None)]]
            isTitan = False
            isJumpDrive = False
            if (eve.session.solarsystemid and eve.session.shipid):
                ship = sm.StartService('godma').GetItem(eve.session.shipid)
                if ship.canJump:
                    isJumpDrive = True
                if (ship.groupID in [const.groupTitan, const.groupBlackOps]):
                    isTitan = True
            checkImCreator = [bool((me.job & const.fleetJobCreator)),
             'You are the fleet boss',
             'You are not the fleet boss']
            checkIfMe = [(charID == eve.session.charid),
             'This is you',
             'This is not you']
            checkIfInSpace = self.GetCheckInSpace()
            checkIsNPC = [util.IsNPC(charID),
             mls.UI_MENUHINT_CHECKISNPC,
             mls.UI_MENUHINT_CHECKISNPCNOT]
            checkIfActiveBeacon = [fleetSvc.HasActiveBeacon(charID),
             mls.UI_MENUHINT_CHECKIFACTIVEBEACON,
             mls.UI_MENUHINT_CHECKIFACTIVEBEACONNOT]
            checkIsTitan = [isTitan,
             'Ship if of Titan class',
             'Ship is not of Titan class']
            checkIsJumpDrive = [isJumpDrive,
             'Ship has a jump drive',
             'Ship does not have a jump drive']
            checkBoosterFleet = [bool((member.roleBooster == const.fleetBoosterFleet)),
             'Member is a fleet booster',
             'Member is not a fleet booster']
            checkBoosterWing = [bool((member.roleBooster == const.fleetBoosterWing)),
             'Member is a wing booster',
             'Member is not a wing booster']
            checkBoosterSquad = [bool((member.roleBooster == const.fleetBoosterSquad)),
             'Member is a squad booster',
             'Member is not a squad booster']
            checkBoosterAny = [bool((checkBoosterFleet[0] or (checkBoosterWing[0] or checkBoosterSquad[0]))),
             'Member is a booster',
             'Member is not a booster']
            checkSubordinate = [(self.CheckImFleetLeaderOrBoss()[0] or (((me.role == const.fleetRoleWingCmdr) and (member.wingID == me.wingID)) or ((me.role == const.fleetRoleSquadCmdr) and (member.squadID == me.squadID)))),
             'You pwn this guy',
             "You don't pwn this guy"]
            checkBoss = [(member.job & const.fleetJobCreator),
             'Is Boss',
             'Is not Boss']
            checkWingCommander = [(member.role == const.fleetRoleWingCmdr),
             'Is Wing Commander',
             'Is not Wing Commander']
            checkSquadCommander = [(member.role == const.fleetRoleSquadCmdr),
             'Is Squad Commander',
             'Is not Squad Commander']
            checkSquadMember = [(member.role == const.fleetRoleMember),
             'Is Squad Member',
             'Is not Squad Member']
            checkFleetCommander = [(member.role == const.fleetRoleLeader),
             'Is Leader',
             'Is not Leader']
            checkBoosterSubordinate = [(checkBoosterAny[0] and ((checkImCreator[0] or (me.role == const.fleetRoleLeader)) or (((checkBoosterWing[0] or checkBoosterSquad[0]) and (me.role == const.fleetRoleWingCmdr)) or (checkBoosterSquad[0] and (me.role == const.fleetRoleSquadCmdr))))),
             'Member is a booster',
             'Member is not a booster']
            checkBoosterSubordinateOrSelf = [(checkBoosterSubordinate[0] or (checkBoosterAny[0] and checkIfMe[0])),
             'Is me or sub',
             'Is not me or sub']
            checkIfFavorite = [(charID in fleetSvc.GetFavorites()),
             'Is Favorite',
             'Is not Favorite']
            checkIfIsBubble = [(shipItem is not None),
             'Is in Bubble',
             'Is Not in Bubble']
            checkMultiSelection = [False,
             mls.UI_MENUHINT_CHECKMULTISELECTION,
             mls.UI_MENUHINT_CHECKMULTISELECTIONNOT]
            dist = sys.maxint
            if otherBall:
                dist = max(0, otherBall.surfaceDist)
            checkWarpDist = [(dist > const.minWarpDistance),
             mls.UI_MENUHINT_CHECKWARPDIST,
             mls.UI_MENUHINT_CHECKWARPDISTNOT]
            checkIsVoiceEnabled = [sm.StartService('vivox').Enabled(),
             'Can mute',
             'Cannot mute']
            checkCanMute = [(fleetSvc.CanIMuteOrUnmuteCharInMyChannel(charID) > 0),
             'Can Mute',
             'Can Not Mute']
            checkCanUnmute = [(fleetSvc.CanIMuteOrUnmuteCharInMyChannel(charID) < 0),
             'Can unmute',
             'Can Not unmute']
            checkIfPrivateMuted = [(charID in vivox.GetMutedParticipants()),
             'Is Muted',
             'Is not Muted']
            myChannelName = mls.UI_FLEET_FLEET
            if (eve.session.fleetrole == const.fleetRoleWingCmdr):
                myChannelName = mls.UI_FLEET_WING
            elif (eve.session.fleetrole == const.fleetRoleSquadCmdr):
                myChannelName = mls.UI_FLEET_SQUAD
            defaultWarpDist = sm.GetService('menu').GetDefaultActionDistance('WarpTo')
            menuEntries = [[mls.UI_CMD_SHOWINFO,
              self.ShowInfo,
              (int(char.Type()),
               charID,
               0,
               None,
               None),
              (checkMultiSelection, False)],
             None,
             [mls.UI_FLEET_KICKMEMBER,
              self.ConfirmMenu(lambda *x: fleetSvc.KickMember(charID)),
              None,
              (checkSubordinate,
               True,
               checkIfMe,
               False,
               checkBoss,
               False)],
             [mls.UI_FLEET_MAKELEADER,
              fleetSvc.MakeLeader,
              (charID),
              (checkIfMe,
               False,
               checkImCreator,
               True)],
             [mls.UI_FLEET_ADDTOWATCHLIST,
              fleetSvc.AddFavorite,
              (charID),
              (checkIfFavorite,
               False,
               checkIfMe,
               False)],
             [mls.UI_FLEET_SETFLEETBOOSTER,
              fleetSvc.SetBooster,
              (charID, const.fleetBoosterFleet),
              (self.CheckImFleetLeaderOrBoss(),
               True,
               checkBoosterAny,
               False,
               checkSubordinate,
               True)],
             [mls.UI_FLEET_SETWINGBOOSTER,
              fleetSvc.SetBooster,
              (charID, const.fleetBoosterWing),
              (checkIfImWingCommanderOrHigher,
               True,
               checkBoosterAny,
               False,
               checkFleetCommander,
               False,
               checkSubordinate,
               True)],
             [mls.UI_FLEET_SETSQUADBOOSTER,
              fleetSvc.SetBooster,
              (charID, const.fleetBoosterSquad),
              (checkBoosterAny,
               False,
               checkWingCommander,
               False,
               checkFleetCommander,
               False,
               checkSubordinate,
               True)],
             [mls.UI_FLEET_REVOKEBOOSTER,
              fleetSvc.SetBooster,
              (charID, const.fleetBoosterNone),
              (checkBoosterSubordinateOrSelf, True)],
             [('%s: %s' % (mls.UI_FLEET_BROADCAST, mls.UI_FLEET_TRAVELTOME)),
              sm.GetService('fleet').SendBroadcast_TravelTo,
              (eve.session.solarsystemid2),
              (checkIfImLeader,
               True,
               checkIfMe,
               True)],
             [mls.UI_CMD_WARPTOMEMBER,
              self.WarpToMember,
              (charID, float(defaultWarpDist)),
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               checkIfMe,
               False),
              'warp'],
             [((mls.UI_CMD_WARPTOMEMBERDIST % {'dist': ''}), menu.ACTIONSGROUP),
              self.WarpToMenu(self.WarpToMember, charID),
              None,
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               checkIfMe,
               False),
              'warp'],
             [mls.UI_CMD_WARPFLEETTOMEMBER,
              self.WarpFleetToMember,
              (charID, float(defaultWarpDist)),
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               self.CheckImFleetLeader(),
               True,
               checkIfMe,
               False),
              'warp'],
             [((mls.UI_CMD_WARPFLEETTOMEMBERDIST % {'dist': ''}), menu.FLEETGROUP),
              self.WarpToMenu(self.WarpFleetToMember, charID),
              None,
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               self.CheckImFleetLeader(),
               True,
               checkIfMe,
               False),
              'warp'],
             [mls.UI_FLEET_WARPWINGTOMEMBER,
              self.WarpFleetToMember,
              (charID, float(defaultWarpDist)),
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               self.CheckImWingCmdr(),
               True,
               checkIfMe,
               False),
              'warp'],
             [((mls.UI_FLEET_WARPWINGTOMEMBERDIST % {'dist': ''}), menu.FLEETGROUP),
              self.WarpToMenu(self.WarpFleetToMember, charID),
              None,
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               self.CheckImWingCmdr(),
               True,
               checkIfMe,
               False),
              'warp'],
             [mls.UI_FLEET_WARPSQUADTOMEMBER,
              self.WarpFleetToMember,
              (charID, float(defaultWarpDist)),
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               self.CheckImSquadCmdr(),
               True,
               checkIfMe,
               False),
              'warp'],
             [((mls.UI_FLEET_WARPSQUADTOMEMBERDIST % {'dist': ''}), menu.FLEETGROUP),
              self.WarpToMenu(self.WarpFleetToMember, charID),
              None,
              (checkWarpDist,
               True,
               checkIfInSpace,
               True,
               self.CheckImSquadCmdr(),
               True,
               checkIfMe,
               False),
              'warp'],
             [mls.UI_CMD_JUMPTOMEMBER,
              self.JumpToMember,
              (charID),
              (checkIfIsBubble,
               False,
               checkIfInSpace,
               True,
               checkIfMe,
               False,
               checkIfActiveBeacon,
               True,
               checkIsJumpDrive,
               True),
              mls.UI_CMD_JUMP],
             [mls.UI_CMD_BRIDGETOMEMBER,
              self.BridgeToMember,
              (charID),
              (checkIfIsBubble,
               False,
               checkIfInSpace,
               True,
               checkIfMe,
               False,
               checkIfActiveBeacon,
               True,
               checkIsTitan,
               True),
              mls.UI_CMD_JUMP],
             [mls.UI_FLEET_REMOVEFROMWATCHLIST,
              fleetSvc.RemoveFavorite,
              (charID),
              (checkIfFavorite, True)],
             [(mls.UI_CMD_MUTEINMYCHANNEL % {'name': myChannelName}),
              fleetSvc.AddToVoiceMute,
              (charID),
              (checkIfMe,
               False,
               checkCanMute,
               True)],
             [(mls.UI_CMD_UNMUTEINMYCHANNEL % {'name': myChannelName}),
              fleetSvc.ExcludeFromVoiceMute,
              (charID),
              (checkCanUnmute, True)],
             [mls.UI_FLEET_MUTEVOICE,
              vivox.MuteParticipantForMe,
              (charID, 1),
              (checkIsVoiceEnabled,
               True,
               checkIfPrivateMuted,
               False,
               checkIfMe,
               False)],
             [mls.UI_FLEET_UNMUTEVOICE,
              vivox.MuteParticipantForMe,
              (charID, 0),
              (checkIsVoiceEnabled,
               True,
               checkIfPrivateMuted,
               True,
               checkIfMe,
               False)],
             [mls.UI_FLEET_LEAVE,
              self.ConfirmMenu(fleetSvc.LeaveFleet),
              None,
              (checkIfMe, True)]]
            menuEntries = ParsedMaybe(menuEntries)
            moveMenu = self.GetFleetMemberMenu2(charID, fleetSvc.MoveMember, True)
            if moveMenu:
                menuEntries.extend([[mls.UI_FLEET_MOVEMEMBER, moveMenu]])
            return menuEntries



    def FleetInviteMenu(self, charID):
        return self.GetFleetMemberMenu2(charID, lambda *args: self.DoInviteToFleet(*args))



    def GetFleetMemberMenu2(self, charID, callback, isMove = False):
        if (session.fleetid is None):
            return []
        else:
            wings = sm.GetService('fleet').GetWings()
            members = sm.GetService('fleet').GetMembers()
            hasFleetCommander = bool([ 1 for guy in members.itervalues() if (guy.role == const.fleetRoleLeader) ])
            wingsWithCommanders = set([ guy.wingID for guy in members.itervalues() if (guy.role == const.fleetRoleWingCmdr) ])
            squadsWithCommanders = set([ guy.squadID for guy in members.itervalues() if (guy.role == const.fleetRoleSquadCmdr) ])
            squads = {}
            for guy in members.itervalues():
                if (guy.squadID not in (None, -1)):
                    squads.setdefault(guy.squadID, []).append(guy)

            myself = members[session.charid]
            member = members.get(charID, None)
            canMoveSquad = (myself.role == const.fleetRoleSquadCmdr)
            canMoveWing = (myself.role == const.fleetRoleWingCmdr)
            canMoveAll = ((myself.role == const.fleetRoleLeader) or (myself.job & const.fleetJobCreator))
            isFreeMove = False
            if (sm.GetService('fleet').GetOptions().isFreeMove and (charID == eve.session.charid)):
                isFreeMove = True
            moveMenu = []
            wingMenu = []
            if (canMoveAll or (canMoveWing or (canMoveSquad or isFreeMove))):
                sortedWings = wings.items()
                sortedWings.sort()
                sortedSquads = []
                for w in wings.itervalues():
                    sortedSquads.extend(w.squads.iterkeys())

                sortedSquads.sort()
                if (canMoveAll or isFreeMove):
                    if ((not hasFleetCommander) and canMoveAll):
                        wingMenu.append([mls.UI_FLEET_FLEETCOMMANDER,
                         callback,
                         (charID,
                          None,
                          None,
                          const.fleetRoleLeader)])
                    if ((member and (member.role in [const.fleetRoleMember, const.fleetRoleSquadCmdr])) and ((member.wingID not in wingsWithCommanders) and canMoveAll)):
                        wingMenu.append([mls.UI_FLEET_WINGCOMMANDER,
                         callback,
                         (charID,
                          member.wingID,
                          None,
                          const.fleetRoleWingCmdr)])
                    if ((member and (member.role == const.fleetRoleMember)) and (member.squadID not in squadsWithCommanders)):
                        wingMenu.append([mls.UI_FLEET_SQUADCOMMANDER,
                         callback,
                         (charID,
                          member.wingID,
                          member.squadID,
                          const.fleetRoleSquadCmdr)])
                    if (member and (member.role == const.fleetRoleSquadCmdr)):
                        wingMenu.append([mls.UI_FLEET_SQUADMEMBER,
                         callback,
                         (charID,
                          member.wingID,
                          member.squadID,
                          const.fleetRoleMember)])
                if not isMove:
                    wingMenu.append([mls.UI_FLEET_FREEPOSITION,
                     callback,
                     (charID,
                      None,
                      None,
                      None)])
                for (wi, (wid, w,),) in enumerate(sortedWings):
                    if ((not (canMoveAll or isFreeMove)) and (wid != myself.wingID)):
                        continue
                    if ((canMoveWing or canMoveAll) and (wid not in wingsWithCommanders)):
                        subsquads = [[mls.UI_FLEET_WINGCOMMANDER,
                          callback,
                          (charID,
                           wid,
                           None,
                           const.fleetRoleWingCmdr)]]
                    else:
                        subsquads = []
                    for (sid, s,) in w.squads.iteritems():
                        if (canMoveSquad and ((not canMoveAll) and (sid != myself.squadID))):
                            continue
                        nMembers = len(squads.get(sid, ()))
                        if ((nMembers >= fleetcommon.MAX_MEMBERS_IN_SQUAD) and ((not member) or (member.squadID != sid))):
                            continue
                        si = (sortedSquads.index(sid) + 1)
                        submembers = []
                        if (sid not in squadsWithCommanders):
                            submembers.append([mls.UI_FLEET_SQUADCOMMANDER,
                             callback,
                             (charID,
                              wid,
                              sid,
                              const.fleetRoleSquadCmdr)])
                        if ((member is None) or ((member.squadID != sid) or (member.role == const.fleetRoleSquadCmdr))):
                            submembers.append([mls.UI_FLEET_SQUADMEMBER,
                             callback,
                             (charID,
                              wid,
                              sid,
                              const.fleetRoleMember)])
                        if submembers:
                            name = s.name
                            if (name == ''):
                                name = ('%s %s' % (mls.UI_FLEET_SQUAD, si))
                            subsquads.append([('%s (%s)' % (name, nMembers)), submembers])

                    if subsquads:
                        name = w.name
                        if (name == ''):
                            name = ('%s %s' % (mls.UI_FLEET_WING, (wi + 1)))
                        wingMenu.append([name, subsquads])

            return wingMenu



    def DoInviteToFleet(self, charID, wingID, squadID, role):
        sm.GetService('fleet').Invite(charID, wingID, squadID, role)



    def CorpMemberMenu(self, charID, multi = 0):
        checkInSameCorp = [(charID in sm.StartService('corp').GetMemberIDs()),
         'You are in the same corporation',
         'You are not in the same corporation']
        checkIAmDirector = [((const.corpRoleDirector & eve.session.corprole) == const.corpRoleDirector),
         "You're a Director",
         "You're not a Director"]
        checkICanKickThem = [((eve.session.charid == charID) or ((const.corpRoleDirector & eve.session.corprole) == const.corpRoleDirector)),
         'You probably can kick them',
         'You probably cant kick them']
        checkIAmCEO = [sm.StartService('corp').UserIsCEO(),
         'You are the CEO',
         'You are not the CEO']
        checkIAmAccountant = [((const.corpRoleAccountant & eve.session.corprole) == const.corpRoleAccountant),
         "You're an accountant",
         "You're not an accountant"]
        checkIBlockRoles = [sm.StartService('corp').UserBlocksRoles(),
         'You block roles',
         'You do not block roles']
        checkIsMe = [(eve.session.charid == charID),
         'It is you',
         'It is not you']
        checkIAmPersonnelMgr = [((const.corpRolePersonnelManager & eve.session.corprole) == const.corpRolePersonnelManager),
         "You're a personnel manager",
         "You're not a personnel manager"]
        checkIsNPC = [util.IsNPC(charID),
         'Character is NPC',
         'Character is not NPC']
        checkIAmInNPCCorp = [util.IsNPC(eve.session.corpid),
         'My corp is NPC',
         'My corp is not NPC']
        checkMultiSelection = [bool(multi),
         mls.UI_MENUHINT_CHECKMULTISELECTION,
         mls.UI_MENUHINT_CHECKMULTISELECTIONNOT]
        quitCorpMenu = [[mls.UI_CMD_REMOVEALLROLES,
          sm.StartService('corp').RemoveAllRoles,
          ()], [mls.UI_CMD_CONFIRMQUITCORP,
          sm.StartService('corp').KickOut,
          (charID)]]
        allowRolesMenu = [[mls.UI_CMD_CONFIRMALLOWROLES,
          sm.StartService('corp').UpdateMember,
          (eve.session.charid,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           None,
           0)]]
        expelMenu = [[mls.UI_CMD_CONFIRMEXPELMEMBER,
          sm.StartService('corp').KickOut,
          (charID)]]
        resignMenu = [[mls.UI_CMD_CONFIRMREASIGNASCEO,
          sm.StartService('corp').ResignFromCEO,
          ()]]
        menuEntries = [None,
         [mls.UI_CMD_VIEWMEMBERDETAILS,
          self.ShowCorpMemberDetails,
          (charID),
          (checkMultiSelection,
           False,
           checkInSameCorp,
           True,
           checkIAmDirector,
           False),
          'any'],
         [mls.UI_CMD_EDITMEMBER,
          self.ShowCorpMemberDetails,
          (charID),
          (checkMultiSelection,
           False,
           checkInSameCorp,
           True,
           checkIAmDirector,
           True),
          'any'],
         [mls.UI_CMD_ALLOWROLES,
          allowRolesMenu,
          None,
          (checkMultiSelection,
           False,
           checkInSameCorp,
           True,
           checkIsMe,
           True,
           checkIBlockRoles,
           True),
          'any'],
         [mls.UI_CMD_TRANSFERCORPCASH,
          sm.StartService('wallet').TransferMoney,
          (eve.session.corpid,
           None,
           charID,
           None),
          (checkMultiSelection,
           False,
           checkIAmAccountant,
           True,
           checkIsNPC,
           False),
          'any'],
         [mls.UI_CMD_QUITCORP,
          quitCorpMenu,
          None,
          (checkInSameCorp,
           True,
           checkICanKickThem,
           True,
           checkIsMe,
           True,
           checkIAmInNPCCorp,
           False,
           checkIAmCEO,
           False),
          'any'],
         [mls.UI_CMD_EXPELMEMBER,
          expelMenu,
          None,
          (checkInSameCorp,
           True,
           checkICanKickThem,
           True,
           checkIsMe,
           False),
          'any'],
         [mls.UI_CMD_REASIGNASCEO,
          resignMenu,
          None,
          (checkInSameCorp,
           True,
           checkIsMe,
           True,
           checkIAmCEO,
           True),
          'any'],
         [mls.UI_CMD_AWARDDECORATION,
          self.AwardDecoration,
          [charID],
          (checkInSameCorp,
           True,
           checkIAmPersonnelMgr,
           True,
           checkIsNPC,
           False),
          'any']]
        return menuEntries



    def AwardDecoration(self, charIDs):
        if not charIDs:
            return 
        if not (type(charIDs) == list):
            charIDs = [charIDs]
        scrolllist = []
        (info, graphics,) = sm.GetService('medals').GetAllCorpMedals(session.corpid)
        options = [ (medal.title, medal.medalID) for medal in info ]
        if (len(options) <= 0):
            raise UserError('MedalCreateToAward')
        cfg.eveowners.Prime(charIDs)
        hintLen = 5
        hint = ', '.join([ cfg.eveowners.Get(charID).name for charID in charIDs[:hintLen] ])
        if (len(charIDs) > hintLen):
            hint += ', ...'
        ret = uix.ListWnd(options, 'generic', mls.UI_CMD_AWARDDECORATION, isModal=1, ordered=1, scrollHeaders=[mls.UI_GENERIC_NAME], hint=hint)
        if ret:
            medalID = ret[1]
            sm.StartService('medals').GiveMedalToCharacters(medalID, charIDs)



    def ShowCorpMemberDetails(self, charID):
        form.CorpMembers().MemberDetails(charID)



    def __GetInviteMenu(self, charID, submenu = None):

        def Invite(charID, channelID):
            sm.StartService('LSC').Invite(charID, channelID)


        inviteMenu = []
        submenus = {}
        for channel in sm.StartService('LSC').GetChannels():
            if (sm.StartService('LSC').IsJoined(channel.channelID) and (type(channel.channelID) == types.IntType)):
                members = sm.StartService('LSC').GetMembers(channel.channelID)
                if (members and (charID not in members)):
                    t = chat.GetDisplayName(channel.channelID).split('\\')
                    if ((submenu and ((len(t) == 2) and (submenu == t[0]))) or ((not submenu) and (len(t) != 2))):
                        inviteMenu += [[t[-1],
                          Invite,
                          (charID, channel.channelID)]]
                    else:
                        if ((not submenu) and (len(t) == 2)):
                            submenus[t[0]] = 1

        for each in submenus.iterkeys():
            inviteMenu += [[each, ('isDynamic',
               self._MenuSvc__GetInviteMenu,
               (charID, each))]]

        inviteMenu.sort()
        inviteMenu = ([[mls.UI_CMD_STARTCONVERSATION,
          Invite,
          (charID, None)]] + inviteMenu)
        return inviteMenu



    def SlashCmd(self, cmd):
        try:
            sm.RemoteSvc('slash').SlashCmd(cmd)
        except RuntimeError:
            import uix
            sm.GetService('gameui').MessageBox('This only works on items at your current location.', 'Oops!', buttons=uix.OK)



    def GetGMTypeMenu(self, typeID, itemID = None, divs = False, unload = False):
        if not (eve.session.role & (service.ROLE_GML | service.ROLE_WORLDMOD)):
            return []
        else:

            def _wrapMulti(command, what = None, maxValue = 2147483647):
                if eve.triapp.uilib.Key(uix.VK_SHIFT):
                    if not what:
                        what = command.split(' ', 1)[0]
                    result = uix.QtyPopup(maxvalue=maxValue, minvalue=1, caption=what, label=mls.UI_GENERIC_QUANTITY, hint='')
                    if result:
                        qty = result['qty']
                    else:
                        return 
                else:
                    qty = 1
                return sm.GetService('slash').SlashCmd((command % qty))


            item = cfg.invtypes.Get(typeID)
            cat = item.categoryID
            if unload:
                if (type(itemID) is tuple):
                    for row in eve.GetInventoryFromId(itemID[0]).ListHardwareModules():
                        if (row.flagID == itemID[1]):
                            itemID = row.itemID
                            break
                    else:
                        itemID = None

                else:
                    charge = self.godma.GetItem(itemID)
                    if (charge.categoryID == const.categoryCharge):
                        for row in eve.GetInventoryFromId(charge.locationID).ListHardwareModules():
                            if ((row.flagID == charge.flagID) and (row.itemID != itemID)):
                                itemID = row.itemID
                                break
                        else:
                            itemID = None

            gm = []
            if divs:
                gm.append(None)
            if (eve.session.role & (service.ROLE_WORLDMOD | service.ROLE_SPAWN)):
                if not eve.session.stationid:
                    if (cat == const.categoryShip):
                        gm.append(('WM: /Spawn this type', lambda *x: _wrapMulti(('/spawnN %%d 4000 %d' % item.typeID), '/Spawn', 50)))
                        gm.append(('WM: /Unspawn this ship', lambda *x: sm.RemoteSvc('slash').SlashCmd(('/unspawn %d' % itemID))))
                    if (cat == const.categoryEntity):
                        gm.append(('WM: /Entity deploy this type', lambda *x: _wrapMulti(('/entity deploy %%d %d' % item.typeID), '/Entity', 100)))
            if ((item.typeID != const.typeSolarSystem) and (cat not in [const.categoryStation, const.categoryOwner])):
                if (eve.session.role & service.ROLE_WORLDMOD):
                    gm.append(('WM: /create this type', lambda *x: _wrapMulti(('/create %d %%d' % item.typeID))))
                gm.append(('GM: /load me this type', lambda *x: _wrapMulti(('/load me %d %%d' % item.typeID))))
            if cfg.IsFittableCategory(cat):
                gm.append(('GM: /fit me this type', lambda *x: _wrapMulti(('/loop %%d /fit me %d' % item.typeID), '/Fit', 8)))
                if unload:
                    if itemID:
                        gm.append(('GM: /unload me this item', lambda *x: sm.RemoteSvc('slash').SlashCmd(('/unload me %d' % itemID))))
                    gm.append(('GM: /unload me this type', lambda *x: sm.RemoteSvc('slash').SlashCmd(('/unload me %d' % item.typeID))))
                    if (itemID and self.godma.GetItem(itemID).damage):
                        gm.append(('GM: Repair this module', lambda *x: sm.RemoteSvc('slash').SlashCmd(('/heal %d' % itemID))))
            if itemID:
                gm.append(('GM: Inspect Attributes',
                 self.InspectAttributes,
                 (itemID, typeID)))
            if (eve.session.role & service.ROLE_PROGRAMMER):
                gm.append(('PROG: Modify Attributes', ('isDynamic',
                  self.AttributeMenu,
                  (itemID, typeID))))
            if divs:
                gm.append(None)
            return gm



    def InspectAttributes(self, itemID, typeID):
        sm.GetService('window').GetWindow('AttributeInspector', create=1, ignoreCurrent=1, itemID=itemID, typeID=typeID)



    def NPCInfoMenu(self, item):
        lst = []
        action = ('gd/type.py?action=Type&typeID=' + str(item.typeID))
        lst.append((mls.GENERIC_MENU_OVERVIEW,
         self.GetFromESP,
         (action)))
        action = ('gd/type.py?action=TypeDogma&typeID=' + str(item.typeID))
        lst.append(('Dogma Attributes',
         self.GetFromESP,
         (action)))
        action = ((('gd/npc.py?action=GetNPCInfo&shipID=' + str(item.itemID)) + '&solarSystemID=') + str(eve.session.solarsystemid))
        lst.append(('Info',
         self.GetFromESP,
         (action)))
        return lst



    def AttributeMenu(self, itemID, typeID):
        d = sm.StartService('info').GetAttrDict(typeID)
        statemgr = sm.StartService('godma').GetStateManager()
        a = statemgr.attributesByID
        lst = []
        for (id, baseValue,) in d.iteritems():
            attrName = a[id].attributeName
            try:
                actualValue = statemgr.GetAttribute(itemID, attrName)
            except:
                sys.exc_clear()
                actualValue = baseValue
            lst.append((('%s - %s' % (attrName, actualValue)),
             self.SetDogmaAttribute,
             (itemID,
              attrName,
              actualValue)))

        lst.sort(lambda x, y: cmp(x[0], y[0]))
        return lst



    def SetDogmaAttribute(self, itemID, attrName, actualValue):
        ret = uix.QtyPopup(None, None, actualValue, ('Set Dogma Attribute for <b>%s</b>' % attrName), 'Set Dogma Attribute', digits=5)
        if ret:
            cmd = ('/dogma %s %s = %s' % (itemID,
             attrName,
             ret['qty']))
            self.SlashCmd(cmd)



    def GagPopup(self, charID, numMinutes):
        reason = 'Gagged for Spamming'
        ret = uix.NamePopup(mls.UI_GENERIC_GAGUSER, mls.UI_GENERIC_ENTERREASON, reason)
        if ret:
            self.SlashCmd(('/gag %s "%s" %s' % (charID,
             ret['name'],
             numMinutes)))



    def ReportISKSpammer(self, charID, channelID):
        if (eve.Message('ConfirmReportISKSpammer', {'name': cfg.eveowners.Get(charID).name}, uix.YESNO) != uix.ID_YES):
            return 
        if (charID == session.charid):
            raise UserError('ReportISKSpammerCannotReportYourself')
        lscSvc = sm.GetService('LSC')
        c = lscSvc.GetChannelWindow(channelID)
        entries = copy.copy(c.output.GetNodes())
        spamEntries = []
        for e in entries:
            if (e.charid == charID):
                (who, txt, charid, time, colorkey,) = e.msg
                spamEntries.append(('[%s] %s > %s' % (util.FmtDate(time, 'nl'),
                 who,
                 txt)))

        if (len(spamEntries) == 0):
            raise UserError('ReportISKSpammerNoEntries')
        spamEntries.reverse()
        spamEntries = spamEntries[:10]
        spammers = getattr(lscSvc, 'spammerList', set())
        if (charID in spammers):
            return 
        spammers.add(charID)
        lscSvc.spammerList = spammers
        c.LoadMessages()
        channel = lscSvc.channels.get(channelID, None)
        if (channel and channel.info):
            channelID = channel.info.displayName
        sm.RemoteSvc('userSvc').ReportISKSpammer(charID, channelID, spamEntries)



    def BanIskSpammer(self, charID):
        if (eve.Message('ConfirmBanIskSpammer', {'name': cfg.eveowners.Get(charID).name}, uix.YESNO) != uix.ID_YES):
            return 
        self.SlashCmd(('/baniskspammer %s' % charID))



    def GagIskSpammer(self, charID):
        if (eve.Message('ConfirmGagIskSpammer', {'name': cfg.eveowners.Get(charID).name}, uix.YESNO) != uix.ID_YES):
            return 
        self.SlashCmd(('/gagiskspammer %s' % charID))



    def GetFromESP(self, action):
        addy = sm.services['machoNet'].namedtransports['ip:packet:server'].transport.address.split(':')[0]
        espaddy = {'87.237.38.51': '87.237.38.15:50001',
         '87.237.38.50': '87.237.38.24:50001',
         '87.237.38.60': '87.237.38.61:50001',
         '87.237.32.22': '87.237.32.22:50001',
         '87.237.38.200': '87.237.38.201:50001'}.get(addy, None)
        if not espaddy:
            espaddy = (addy + ':50001')
        blue.os.ShellExecute(('http://%s/%s' % (espaddy, action)))



    def GetGMMenu(self, itemID = None, slimItem = None, charID = None, invItem = None, mapItem = None):
        if not (eve.session.role & (service.ROLE_GML | service.ROLE_WORLDMOD)):
            if (charID and (eve.session.role & service.ROLE_LEGIONEER)):
                return [(mls.UI_CMD_GAGISKSPAMMER,
                  self.GagIskSpammer,
                  (charID))]
            else:
                return []
            gm = [(str((itemID or charID)),
              blue.pyos.SetClipboardData,
              (str((itemID or charID))))]
            if (mapItem and (not slimItem)):
                gm.append(('TR me here!',
                 sm.RemoteSvc('slash').SlashCmd,
                 (('/tr me ' + str(mapItem.itemID)))))
                gm.append(None)
            elif charID:
                gm.append((('TR me to %s' % cfg.eveowners.Get(charID).name),
                 sm.RemoteSvc('slash').SlashCmd,
                 (('/tr me ' + str(charID)))))
                gm.append(None)
            elif slimItem:
                gm.append(('TR me here!',
                 sm.RemoteSvc('slash').SlashCmd,
                 (('/tr me ' + str(itemID)))))
                gm.append(None)
            if invItem:
                gm += [(mls.UI_CMD_COPYIDQTY,
                  self.CopyItemIDAndMaybeQuantityToClipboard,
                  (invItem))]
                typeText = ('copy typeID (%s)' % invItem.typeID)
                gm += [(typeText,
                  blue.pyos.SetClipboardData,
                  (str(invItem.typeID)))]
                if ((invItem.flagID == const.flagHangar) and ((invItem.locationID == eve.session.stationid) and (invItem.itemID not in (eve.session.shipid, eve.session.charid)))):
                    gm.append((mls.UI_CMD_TAKEOUTTRASH,
                     self.TakeOutTrash,
                     [[invItem]]))
                gm.append((mls.UI_CMD_EDIT,
                 self.GetAdamEditType,
                 [invItem.typeID]))
            if (charID and (not util.IsNPC(charID))):
                action = ('gm/character.py?action=Character&characterID=' + str(charID))
                gm.append((mls.UI_GENERIC_SHOWINESP,
                 self.GetFromESP,
                 (action)))
                gm.append(None)
                (gm.append((mls.UI_CMD_GAGISKSPAMMER,
                  self.GagIskSpammer,
                  (charID))))
                gm.append((mls.UI_CMD_BANISKSPAMMER,
                 self.BanIskSpammer,
                 (charID)))
                action = ('gm/users.py?action=BanUserByCharacterID&characterID=' + str(charID))
                gm.append((mls.UI_GENERIC_BANUSERESP,
                 self.GetFromESP,
                 (action)))
                gm += [('Gag User', [(('30 ' + mls.UI_GENERIC_MINUTES),
                    self.GagPopup,
                    (charID, 30)),
                   (('1 ' + mls.UI_GENERIC_HOUR),
                    self.GagPopup,
                    (charID, 60)),
                   (('6 ' + mls.UI_GENERIC_HOURS),
                    self.GagPopup,
                    (charID, 360)),
                   (('24 ' + mls.UI_GENERIC_HOURS),
                    self.GagPopup,
                    (charID, 1440)),
                   None,
                   (mls.UI_GENERIC_UNGAG, lambda *x: self.SlashCmd(('/ungag %s' % charID)))])]
            gm.append(None)
            item = (slimItem or invItem)
            if item:
                locationID = item.locationID
                if eve.session.stationid:
                    locationID = sm.GetService('invCache').GetStationIDOfficeFolderIDOfficeIDOfItem(item)[0]
                if ((item.categoryID == const.categoryShip) and (item.singleton or (not eve.session.stationid))):
                    import dna
                    if ((item.ownerID in [eve.session.corpid, eve.session.charid]) or (eve.session.role & service.ROLE_WORLDMOD)):
                        try:
                            menu = dna.Ship().ImportFromShip(shipID=item.itemID, ownerID=item.ownerID, deferred=True).GetMenuInline(spiffy=False, fit=(item.itemID != eve.session.shipid))
                            gm.append(('Copycat', menu))
                        except RuntimeError:
                            pass
                    gm += [('/Online modules', lambda shipID = item.itemID: self.SlashCmd(('/online %d' % shipID)))]
                gm += self.GetGMTypeMenu(item.typeID, itemID=item.itemID)
                if ((getattr(slimItem, 'categoryID', None) == const.categoryEntity) or (getattr(slimItem, 'groupID', None) == const.groupWreck)):
                    gm.append(('NPC Info', ('isDynamic',
                      self.NPCInfoMenu,
                      (item))))
                gm.append(None)
            if (eve.session.role & service.ROLE_CONTENT):
                if slimItem:
                    if (getattr(slimItem, 'dunObjectID', None) != None):
                        if not sm.StartService('scenario').IsSelected(itemID):
                            gm.append((mls.UI_CMD_ADDTOSELECTION,
                             sm.StartService('scenario').AddSelected,
                             (itemID)))
                        else:
                            gm.append((mls.UI_CMD_REMOVEFROMSELECTION,
                             sm.StartService('scenario').RemoveSelected,
                             (itemID)))
            if slimItem:
                itemID = slimItem.itemID
                typeID = slimItem.typeID
                groupID = slimItem.groupID
                categoryID = slimItem.categoryID
                graphicID = cfg.invtypes.Get(slimItem.typeID).graphicID
                graphicFile = util.GraphicFile(graphicID)
                if (graphicFile is ''):
                    graphicFile = None
                subMenu = self.GetGMStructureStateMenu(itemID, slimItem, charID, invItem, mapItem)
                if (len(subMenu) > 0):
                    gm += [('Change State', subMenu)]
                gm += self.GetGMBallsAndBoxesMenu(itemID, slimItem, charID, invItem, mapItem)
                gm.append(None)
                gm.append((('charID: ' + self.GetOwnerLabel(slimItem.charID)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.charID))))
                gm.append((('ownerID: ' + self.GetOwnerLabel(slimItem.ownerID)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.ownerID))))
                gm.append((('corpID: ' + self.GetOwnerLabel(slimItem.corpID)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.corpID))))
                gm.append((('allianceID: ' + self.GetOwnerLabel(slimItem.allianceID)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.allianceID))))
                gm.append(None)
                gm.append(((('typeID: ' + str(slimItem.typeID)) + (' (%s)' % cfg.invtypes.Get(slimItem.typeID).name)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.typeID))))
                gm.append(((('groupID: ' + str(slimItem.groupID)) + (' (%s)' % cfg.invgroups.Get(slimItem.groupID).name)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.groupID))))
                gm.append(((('categID: ' + str(slimItem.categoryID)) + (' (%s)' % cfg.invcategories.Get(slimItem.categoryID).name)),
                 blue.pyos.SetClipboardData,
                 (str(slimItem.categoryID))))
                gm.append((('graphicID: ' + str(graphicID)),
                 blue.pyos.SetClipboardData,
                 (str(graphicID))))
                gm.append((('graphicFile: ' + str(graphicFile)),
                 blue.pyos.SetClipboardData,
                 (str(graphicFile))))
                gm.append(None)
                gm.append(('Copy Coordinates',
                 self.CopyCoordinates,
                 (itemID)))
                gm.append(None)
            gm.append(('Toggle Menu debug info', self.ToggleMenuDebug))
            gm.append(None)
            dict = {'CHARID': charID,
             'ITEMID': itemID,
             'ID': (charID or itemID)}
            for i in range(20):
                item = prefs.GetValue(('gmmenuslash%d' % i), None)
                if item:
                    for (k, v,) in dict.iteritems():
                        if (((' %s ' % k) in item) and v):
                            item = item.replace(k, str(v))
                            break

                else:
                    gm.append((item,
                     sm.RemoteSvc('slash').SlashCmd,
                     (item)))
                    continue

            return gm



    def GetGMStructureStateMenu(self, itemID = None, slimItem = None, charID = None, invItem = None, mapItem = None):
        subMenu = []
        if (hasattr(slimItem, 'posState') and (slimItem.posState is not None)):
            currentState = slimItem.posState
            if (currentState not in pos.ONLINE_STABLE_STATES):
                if (currentState == pos.STRUCTURE_ANCHORED):
                    subMenu.append(('Online',
                     sm.RemoteSvc('slash').SlashCmd,
                     (('/pos online ' + str(itemID)))))
                    subMenu.append(('Unanchor',
                     sm.RemoteSvc('slash').SlashCmd,
                     (('/pos unanchor ' + str(itemID)))))
                else:
                    if (currentState == pos.STRUCTURE_UNANCHORED):
                        subMenu.append(('Anchor',
                         sm.RemoteSvc('slash').SlashCmd,
                         (('/pos anchor ' + str(itemID)))))
            elif (getattr(slimItem, 'posTimestamp', None) is not None):
                subMenu.append(('Complete State',
                 sm.RemoteSvc('slash').SlashCmd,
                 (('/sov complete ' + str(itemID)))))
            subMenu.append(('Offline',
             sm.RemoteSvc('slash').SlashCmd,
             (('/pos offline ' + str(itemID)))))
        if (hasattr(slimItem, 'structureState') and ((slimItem.structureState != None) and (slimItem.structureState in [pos.STRUCTURE_SHIELD_REINFORCE, pos.STRUCTURE_ARMOR_REINFORCE]))):
            subMenu.append(('Complete State',
             sm.RemoteSvc('slash').SlashCmd,
             (('/sov complete ' + str(itemID)))))
        return subMenu



    def GetGMBallsAndBoxesMenu(self, itemID = None, slimItem = None, charID = None, invItem = None, mapItem = None):
        spaceMgr = sm.StartService('space')
        partMenu = [('Stop partition box display ',
          spaceMgr.StopPartitionDisplayTimer,
          ()),
         None,
         ('Start partition box display limit = 0',
          spaceMgr.StartPartitionDisplayTimer,
          (0,)),
         ('Start partition box display limit = 1',
          spaceMgr.StartPartitionDisplayTimer,
          (1,)),
         ('Start partition box display limit = 2',
          spaceMgr.StartPartitionDisplayTimer,
          (2,)),
         ('Start partition box display limit = 3',
          spaceMgr.StartPartitionDisplayTimer,
          (3,)),
         ('Start partition box display limit = 4',
          spaceMgr.StartPartitionDisplayTimer,
          (4,)),
         ('Start partition box display limit = 5',
          spaceMgr.StartPartitionDisplayTimer,
          (5,)),
         ('Start partition box display limit = 6',
          spaceMgr.StartPartitionDisplayTimer,
          (6,)),
         ('Start partition box display limit = 7',
          spaceMgr.StartPartitionDisplayTimer,
          (7,)),
         None,
         ('Show single level',
          self.ChangePartitionLevel,
          (0,)),
         ('Show selected level and up',
          self.ChangePartitionLevel,
          (1,))]
        subMenu = [('Balls & Boxes', [('Show miniballs',
            self.ShowDestinyBalls,
            (itemID)),
           None,
           ('Wireframe Destiny Ball',
            self.BallsUp,
            (itemID, True)),
           ('Wireframe Model Ball',
            self.BallsUp,
            (itemID, False)),
           ('Wireframe BoundingSphere',
            self.BallsUp,
            (itemID, -1)),
           None,
           ('Partition', partMenu)])]
        return subMenu



    def GetOwnerLabel(self, ownerID):
        name = ''
        if (ownerID != None):
            try:
                name = ((' (' + cfg.eveowners.Get(ownerID).name) + ')    ')
            except:
                sys.exc_clear()
        return (str(ownerID) + name)



    def GetAdamEditType(self, typeID):
        uthread.new(self.ClickURL, ('http://adam:50001/gd/type.py?action=EditTypeDogmaForm&typeID=%s' % typeID))



    def ClickURL(self, url, *args):
        blue.os.ShellExecute(url)



    def ToggleMenuDebug(self):
        settings.user.ui.Set('showInactiveMenus', (not settings.user.ui.Get('showInactiveMenus', 0)))



    def SolarsystemScanMenu(self, scanResultID):
        warptoLabel = self.DefaultWarpToLabel()
        defaultWarpDist = self.GetDefaultActionDistance('WarpTo')
        ret = [(warptoLabel,
          self.WarpToScanResult,
          (scanResultID, defaultWarpDist)), (((mls.UI_CMD_WARPTOWITHIN % {'dist': ''}), menu.ACTIONSGROUP), self.WarpToMenu(self.WarpToScanResult, scanResultID))]
        if self.CheckImFleetLeader()[0]:
            ret.extend([(mls.UI_CMD_WARPFLEET,
              self.WarpFleetToScanResult,
              (scanResultID, float(defaultWarpDist))), (((mls.UI_CMD_WARPFLEETTOWITHIN % {'dist': ''}), menu.FLEETGROUP), self.WarpToMenu(self.WarpFleetToScanResult, scanResultID))])
        elif self.CheckImWingCmdr()[0]:
            ret.extend([(mls.UI_CMD_WARPWING,
              self.WarpFleetToScanResult,
              (scanResultID, float(defaultWarpDist))), (((mls.UI_CMD_WARPWINGTOWITHIN % {'dist': ''}), menu.FLEETGROUP), self.WarpToMenu(self.WarpFleetToScanResult, scanResultID))])
        elif self.CheckImSquadCmdr()[0]:
            ret.extend([(mls.UI_CMD_WARPSQUAD,
              self.WarpFleetToScanResult,
              (scanResultID, float(defaultWarpDist))), (((mls.UI_CMD_WARPSQUADTOWITHIN % {'dist': ''}), menu.FLEETGROUP), self.WarpToMenu(self.WarpFleetToScanResult, scanResultID))])
        return ret



    def WarpToScanResult(self, scanResultID, minRange = None):
        self._WarpXToScanResult(scanResultID, minRange)



    def WarpFleetToScanResult(self, scanResultID, minRange = None):
        self._WarpXToScanResult(scanResultID, minRange, fleet=True)



    def _WarpXToScanResult(self, scanResultID, minRange = None, fleet = False):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            bp.WarpToStuff('scan', scanResultID, minRange=minRange, fleet=fleet)
            sm.StartService('space').WarpDestination(scanResultID, None, None)



    def CelestialMenu(self, itemID, mapItem = None, slimItem = None, noTrace = 0, typeID = None, parentID = None, bookmark = None, itemIDs = [], showInactive = 0, ignoreTypeCheck = 0, ignoreDroneMenu = 0, filterFunc = None, hint = None, ignoreMarketDetails = 1):
        if (type(itemID) == list):
            menus = []
            for data in itemID:
                menus.append(self._CelestialMenu(data, showInactive, ignoreTypeCheck, ignoreDroneMenu, filterFunc, hint, ignoreMarketDetails, (len(itemID) > 1)))

            return self.MergeMenus(menus)
        else:
            ret = self._CelestialMenu((itemID,
             mapItem,
             slimItem,
             noTrace,
             typeID,
             parentID,
             bookmark), showInactive, ignoreTypeCheck, ignoreDroneMenu, filterFunc, hint, ignoreMarketDetails)
            return self.MergeMenus([ret])



    def _CelestialMenu(self, data, showInactive = 0, ignoreTypeCheck = 0, ignoreDroneMenu = 0, filterFunc = None, hint = None, ignoreMarketDetails = 1, multi = 0):
        (itemID, mapItem, slimItem, noTrace, typeID, parentID, bookmark,) = data
        showInactive = (showInactive or settings.user.ui.Get('showInactiveMenus', 0))
        categoryID = None
        bp = sm.StartService('michelle').GetBallpark()
        fleetSvc = sm.GetService('fleet')
        if bp:
            slimItem = (slimItem or bp.GetInvItem(itemID))
        if slimItem:
            typeID = slimItem.typeID
            parentID = (sm.StartService('map').GetParent(itemID) or eve.session.solarsystemid)
            categoryID = slimItem.categoryID
        mapItemID = None
        if bookmark:
            typeID = bookmark.typeID
            parentID = bookmark.locationID
            itemID = (itemID or bookmark.locationID)
        else:
            mapItem = (mapItem or sm.StartService('map').GetItem(itemID))
            if mapItem:
                typeID = mapItem.typeID
                parentID = (getattr(mapItem, 'locationID', None) or const.locationUniverse)
                if (typeID == const.groupSolarSystem):
                    mapItemID = mapItem.itemID
        if ((typeID is None) or (categoryID and (categoryID == const.categoryCharge))):
            return []
        invType = cfg.invtypes.Get(typeID)
        groupID = invType.groupID
        invGroup = cfg.invgroups.Get(groupID)
        groupName = invGroup.name
        categoryID = (categoryID or invGroup.categoryID)
        invCategory = cfg.invcategories.Get(categoryID)
        categoryName = invCategory.name
        godmaSM = self.godma.GetStateManager()
        shipItem = self.godma.GetStateManager().GetItem(eve.session.shipid)
        isMyShip = (itemID == eve.session.shipid)
        otherBall = ((bp and bp.GetBall(itemID)) or None)
        ownBall = ((bp and bp.GetBall(eve.session.shipid)) or None)
        dist = (otherBall and max(0, otherBall.surfaceDist))
        otherCharID = (slimItem and ((slimItem.charID or slimItem.ownerID) or None))
        badCateg = (mls.UI_MENUHINT_BADTYPE % invCategory.name)
        badGroup = (mls.UI_MENUHINT_BADTYPE % groupName)
        badType = (mls.UI_MENUHINT_BADTYPE % invType.name)
        if ((parentID is None) and ((groupID == const.groupStation) and itemID)):
            tmp = sm.StartService('ui').GetStation(itemID)
            if (tmp is not None):
                parentID = tmp.solarSystemID
        if (bookmark and (bookmark.locationID and (bookmark.locationID == session.solarsystemid))):
            myLoc = ((ownBall and trinity.TriVector(ownBall.x, ownBall.y, ownBall.z)) or None)
            if (((bookmark.typeID == const.typeSolarSystem) or (bookmark.itemID == bookmark.locationID)) and (bookmark.x is not None)):
                location = None
                if (hasattr(bookmark, 'locationType') and (bookmark.locationType in ('agenthomebase', 'objective'))):
                    entryPoint = sm.StartService('agents').GetAgentMoniker(bookmark.agentID).GetEntryPoint()
                    if (entryPoint is not None):
                        location = (trinity.TriVector(*entryPoint) or None)
                if (location is None):
                    location = (trinity.TriVector(bookmark.x, bookmark.y, bookmark.z) or None)
                dist = ((myLoc and (location and (myLoc - location).Length())) or 0.0)
            else:
                dist = 0.0
                if (bookmark.itemID in bp.balls):
                    b = bp.balls[bookmark.itemID]
                    dist = b.surfaceDist
                    location = trinity.TriVector(b.x, b.y, b.z)
        checkMultiCategs1 = [(categoryID in (const.categoryEntity,
          const.categoryDrone,
          const.categoryShip)),
         ('This is %s' % categoryName),
         ('This is not %s, %s nor %s' % (cfg.invcategories.Get(const.categoryEntity).name,
          cfg.invcategories.Get(const.categoryDrone).name,
          cfg.invcategories.Get(const.categoryShip).name))]
        niceRange = ((dist and util.FmtDist(dist)) or mls.UI_MENU_NODISTANCE)
        checkIsMine = [(bool(slimItem) and (slimItem.ownerID == eve.session.charid)),
         'You own this item',
         "You don't own this item"]
        checkIsMyCorps = [(bool(slimItem) and (slimItem.ownerID == eve.session.corpid)),
         'Your corporation own this item',
         "Your corporation doesn't own this item"]
        checkIsMineOrCorps = [(bool(slimItem) and ((slimItem.ownerID == eve.session.charid) or (slimItem.ownerID == eve.session.corpid))),
         'You or your corp is the owner this item',
         'You and not your corp is the owner this item']
        checkIsMineOrCorpsOrAlliances = [(bool(slimItem) and ((slimItem.ownerID == eve.session.charid) or ((slimItem.ownerID == eve.session.corpid) or (eve.session.allianceid and (slimItem.allianceID == eve.session.allianceid))))),
         mls.UI_MENUHINT_CHECKISMINEORCORPSORALLIANCES,
         mls.UI_MENUHINT_CHECKISMINEORCORPSORALLIANCESNOT]
        checkIsMineOrCorpsOrFleets = [(bool(slimItem) and ((slimItem.ownerID == eve.session.charid) or ((slimItem.ownerID == eve.session.corpid) or (slimItem.ownerID in sm.GetService('fleet').GetMembers().keys())))),
         'You or your corp or your fleet mate is the owner this item',
         'Neither you, your corp or your fleetmate is the owner this item']
        checkIsFree = [(bool(otherBall) and otherBall.isFree),
         'This item is free',
         'This item is not free!!']
        checkBP = [bool(bp),
         mls.UI_MENUHINT_CHECKBP,
         mls.UI_MENUHINT_CHECKBPNOT]
        checkMyShip = [isMyShip,
         mls.UI_MENUHINT_CHECKMYSHIP,
         mls.UI_MENUHINT_CHECKMYSHIPNOT]
        checkInCapsule = [((itemID == eve.session.shipid) and (groupID == const.groupCapsule)),
         mls.UI_MENUHINT_CHECKINCAPSULE,
         mls.UI_MENUHINT_CHECKINCAPSULENOT]
        checkShipBusy = [(bool(otherBall) and otherBall.isInteractive),
         mls.UI_MENUHINT_PILOTINSHIP,
         'Ship is available']
        checkInSpace = [bool(eve.session.solarsystemid),
         mls.UI_MENUHINT_CHECKINSPACE,
         mls.UI_MENUHINT_CHECKINSPACENOT]
        checkInSystem = [((dist is not None) and ((bp and (itemID in bp.balls)) or (parentID == eve.session.solarsystemid))),
         mls.UI_MENUHINT_CHECKINSYSTEM,
         mls.UI_MENUHINT_CHECKINSYSTEMNOT]
        checkIsObserving = [sm.GetService('target').IsObserving(),
         'is observing',
         'is not observing']
        checkStation = [(groupID == const.groupStation),
         mls.UI_MENUHINT_CHECKSTATION,
         mls.UI_MENUHINT_CHECKSTATIONNOT]
        checkPlanetCargoLink = [(groupID == const.groupPlanetaryCustomsOffices),
         'This is a cargo link',
         'This is not a cargo link']
        checkPlanet = [(groupID == const.groupPlanet),
         'This is a planet',
         'This is not a planet']
        checkMoon = [(groupID == const.groupMoon),
         'This is a moon',
         'This is not a moon']
        checkThisPlanetOpen = [(sm.GetService('planetUI').IsOpen() and (sm.GetService('planetUI').planetID == itemID)),
         'This planet is open in viewer',
         'This planet is not open in viewer']
        checkStargate = [(bool(slimItem) and (groupID == const.groupStargate)),
         mls.UI_MENUHINT_CHECKSTARGATE,
         mls.UI_MENUHINT_CHECKSTARGATENOT]
        checkWarpgate = [(groupID == const.groupWarpGate),
         mls.UI_MENUHINT_CHECKWARPGATE,
         mls.UI_MENUHINT_CHECKWARPGATENOT]
        checkWormhole = [(groupID == const.groupWormhole),
         'This is a wormhole',
         'This is not a wormhole']
        checkCapsule = [((shipItem is not None) and (shipItem.groupID == const.groupCapsule)),
         'You are in capsule',
         'You are not in capsule']
        checkControlTower = [(groupID == const.groupControlTower),
         'This is a control tower',
         'This is not a control tower']
        checkSentry = [(groupID in (const.groupMobileMissileSentry,
          const.groupMobileProjectileSentry,
          const.groupMobileHybridSentry)),
         'This is a sentry structure',
         'This is not a sentry structure']
        checkLaserSentry = [(groupID == const.groupMobileLaserSentry),
         'This is a mobile laser sentry',
         'This is not a mobile laser sentry']
        checkShipMaintainer = [(groupID == const.groupShipMaintenanceArray),
         'This is a ship maintenance array',
         'This is not a ship maintenance array']
        checkCorpHangarArray = [(groupID == const.groupCorporateHangarArray),
         'This is a corp hangar array',
         'This is not a corp hangar array']
        checkAssemblyArray = [(groupID == const.groupAssemblyArray),
         'This is an assembly array',
         'This is not an assembly array']
        checkMobileLaboratory = [(groupID == const.groupMobileLaboratory),
         'This is a mobile laboratory',
         'This is not a mobile laboratory']
        checkHarvester = [(groupID == const.groupMoonMining),
         'This is a harvester',
         'This is not a harvester']
        checkSilo = [(groupID == const.groupSilo),
         'This is a silo',
         'This is not a silo']
        checkReactor = [(groupID == const.groupMobileReactor),
         'This is a mobile reactor',
         'This is not a mobile reactor']
        checkRefinery = [(groupID == const.groupRefiningArray),
         'This is a refinery',
         'This is not a refinery']
        checkContainer = [(groupID in (const.groupWreck,
          const.groupCargoContainer,
          const.groupSpawnContainer,
          const.groupSecureCargoContainer,
          const.groupAuditLogSecureContainer,
          const.groupFreightContainer,
          const.groupDeadspaceOverseersBelongings,
          const.groupMissionContainer)),
         'This is container',
         'This is not container']
        checkCynoField = [(typeID == const.typeCynosuralFieldI),
         'This is a Cynosural Field',
         'This is not a Cynosural Field']
        checkConstructionPf = [(groupID in (const.groupConstructionPlatform,
          const.groupStationUpgradePlatform,
          const.groupStationImprovementPlatform)),
         'This is construction platform',
         'This is not construction platform']
        checkShip = [(categoryID == const.categoryShip),
         'This is ship',
         'This is not ship']
        checkSpacePig = [(((groupID == const.groupAgentsinSpace) or (groupID == const.groupDestructibleAgentsInSpace)) and (not (not sm.StartService('godma').GetType(typeID).agentID))),
         mls.UI_MENUHINT_CHECKSPACEPIG,
         mls.UI_MENUHINT_CHECKSPACEPIGNOT]
        checkIfShipMAShip = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).hasShipMaintenanceBay))),
         'This is a ship maintenance array (ship)',
         'This is not a ship maintenance array (ship)']
        checkIfShipCHShip = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).hasCorporateHangars))),
         'This has corporate hangars (ship)',
         'This does not have corporate hangars (ship)']
        checkShipConfig = [checkIfShipMAShip[0],
         'This ship has configurable stuff',
         'This ship does not have configurable stuff']
        checkSolarSystem = [(groupID == const.groupSolarSystem),
         'This is a solar system',
         'This is not a solar system']
        checkWreck = [(groupID == const.groupWreck),
         'This is a wreck',
         'This is not a wreck']
        checkIfShipFuelBay = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialFuelBayCapacity))),
         'This ship has a special fuel bay',
         'This ship does not have a special fuel bay']
        checkIfShipOreHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialOreHoldCapacity))),
         'This ship has a specialized ore hold',
         'This ship does not have a specialized ore hold']
        checkIfShipGasHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialGasHoldCapacity))),
         'This ship has a specialized gas hold',
         'This ship does not have a specialized gas hold']
        checkIfShipMineralHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialMineralHoldCapacity))),
         'This ship has a specialized mineral hold',
         'This ship does not have a specialized mineral hold']
        checkIfShipSalvageHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialSalvageHoldCapacity))),
         'This ship has a specialized salvage hold',
         'This ship does not have a specialized salvage hold']
        checkIfShipShipHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialShipHoldCapacity))),
         'This ship has a specialized ship hold',
         'This ship does not have a specialized ship hold']
        checkIfShipSmallShipHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialSmallShipHoldCapacity))),
         'This ship has a specialized small ship hold',
         'This ship does not have a specialized small ship hold']
        checkIfShipMediumShipHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialMediumShipHoldCapacity))),
         'This ship has a specialized medium ship hold',
         'This ship does not have a specialized medium ship hold']
        checkIfShipLargeShipHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialLargeShipHoldCapacity))),
         'This ship has a specialized large ship hold',
         'This ship does not have a specialized large ship hold']
        checkIfShipIndustrialShipHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialIndustrialShipHoldCapacity))),
         'This ship has a specialized industrial ship hold',
         'This ship does not have a specialized industrial ship hold']
        checkIfShipAmmoHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialAmmoHoldCapacity))),
         'This ship has a specialized ammo hold',
         'This ship does not have a specialized ammo hold']
        checkIfShipCommandCenterHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialCommandCenterHoldCapacity))),
         'This ship has a specialized command center hold',
         'This ship does not have a specialized command center hold']
        checkIfShipPlanetaryCommoditiesHold = [(slimItem and ((categoryID == const.categoryShip) and bool(godmaSM.GetType(typeID).specialPlanetaryCommoditiesHoldCapacity))),
         'This ship has a specialized planetary commodities hold',
         'This ship does not have a specialized planetary commodities hold']
        maxTransferDistance = max(getattr(godmaSM.GetType(typeID), 'maxOperationalDistance', 0), const.maxCargoContainerTransferDistance)
        checkWarpDist = [((dist is not None) and (dist > const.minWarpDistance)),
         mls.UI_MENUHINT_CHECKWARPDIST,
         mls.UI_MENUHINT_CHECKWARPDISTNOT]
        checkApproachDist = [((dist is not None) and (dist < const.minWarpDistance)),
         mls.UI_MENUHINT_CHECKAPPROACHDIST,
         mls.UI_MENUHINT_CHECKAPPROACHDISTNOT]
        checkAlignTo = [((dist is not None) and (dist > const.minWarpDistance)),
         mls.UI_MENUHINT_CHECKAPPROACHDIST,
         mls.UI_MENUHINT_CHECKAPPROACHDISTNOT]
        checkJumpDist = [((dist is not None) and (dist < const.maxStargateJumpingDistance)),
         mls.UI_MENUHINT_CHECKJUMPDIST,
         mls.UI_MENUHINT_CHECKJUMPDISTNOT]
        checkWormholeDist = [((dist is not None) and (dist < const.maxWormholeEnterDistance)),
         mls.UI_MENUHINT_CHECKWORMHOLEDIST,
         mls.UI_MENUHINT_CHECKWORMHOLEDISTNOT]
        checkTransferDist = [((dist is not None) and (dist < maxTransferDistance)),
         mls.UI_MENUHINT_CHECKTRANSFERDIST,
         mls.UI_MENUHINT_CHECKTRANSFERDISTNOT]
        checkConfigDist = [((dist is not None) and (dist < const.maxConfigureDistance)),
         mls.UI_MENUHINT_CHECKCONFIGDIST,
         mls.UI_MENUHINT_CHECKCONFIGDISTNOT]
        checkLookatDist = [((dist is not None) and ((dist < 100000.0) or checkIsObserving[0])),
         mls.UI_MENUHINT_CHECKLOOKATDIST,
         mls.UI_MENUHINT_CHECKLOOKATDISTNOT]
        checkDist1000000 = [((dist is not None) and ((dist > 1000000) or checkIsObserving[0])),
         mls.UI_MENUHINT_CHECKDIST1000000,
         mls.UI_MENUHINT_CHECKDIST1000000NOT]
        checkTargetingRange = [((dist is not None) and ((shipItem is not None) and (shipItem and (dist < shipItem.maxTargetRange)))),
         mls.UI_MENUHINT_CHECKTARGETINGRANGE,
         mls.UI_MENUHINT_CHECKTARGETINGRANGENOT]
        checkSpacePigDist = [((dist is not None) and (dist < sm.StartService('godma').GetType(typeID).agentCommRange)),
         ('Within communications range (%d m)' % sm.StartService('godma').GetType(typeID).agentCommRange),
         ('Outside of communications range (%d m)' % sm.StartService('godma').GetType(typeID).agentCommRange)]
        checkDistNone = [(dist is None),
         'distance is None',
         'distance is not None']
        checkWarpActive = [(ownBall and (ownBall.mode == destiny.DSTBALL_WARP)),
         mls.UI_MENUHINT_CHECKWARPACTIVE,
         mls.UI_MENUHINT_CHECKWARPACTIVENOT]
        checkCanUseGate = [(slimItem and ((shipItem is not None) and (not shipItem.canNotUseStargates))),
         mls.UI_MENUHINT_CHECKCANUSEGATE,
         mls.UI_MENUHINT_CHECKCANUSEGATENOT]
        checkJumpThrough = [(slimItem and sm.GetService('fleet').CanJumpThrough(slimItem)),
         'Ship allowed to jump through',
         'Ship not allowed to jump through']
        checkWreckViewed = [(checkWreck[0] and sm.GetService('wreck').IsViewedWreck(itemID)),
         'This is a viewed wreck',
         'This is not a viewed wreck']
        checkFleet = [bool(eve.session.fleetid),
         mls.UI_MENUHINT_CHECKFLEET,
         mls.UI_MENUHINT_CHECKFLEETNOT]
        checkIfImLeader = [self.ImFleetLeaderOrCommander(),
         mls.UI_MENUHINT_CHECKIFIMLEADER,
         mls.UI_MENUHINT_CHECKIFIMLEADERNOT]
        checkIfImCommander = [self.ImFleetCommander(),
         mls.UI_MENUHINT_CHECKIFIMLEADER,
         mls.UI_MENUHINT_CHECKIFIMLEADERNOT]
        checkEnemySpotted = [sm.GetService('fleet').CurrentFleetBroadcastOnItem(itemID, state.gbEnemySpotted),
         'This object is the nearID of the latest EnemySpotted fleet broadcast.',
         'This object is not the nearID of the latest EnemySpotted fleet broadcast.']
        checkHasMarketGroup = [((cfg.invtypes.Get(typeID).marketGroupID is not None) and (not ignoreMarketDetails)),
         'Item type has market group',
         'Item type does not have a market group']
        checkIsPublished = [cfg.invtypes.Get(typeID).published,
         'Item type is published',
         'Item type is not published']
        checkMultiSelection = [bool(multi),
         mls.UI_MENUHINT_CHECKMULTISELECTION,
         mls.UI_MENUHINT_CHECKMULTISELECTIONNOT]
        checkIfIsPreview = [((categoryID in const.previewCategories) or (groupID in const.previewGroups)),
         'Can be previewed',
         'Cannot be previewd']
        checkIfLandmark = [(itemID and (itemID < 0)),
         'This is a landmark',
         'This is not a Landmark']
        checkIfAgentBookmark = [(bookmark and (getattr(bookmark, 'agentID', 0) and hasattr(bookmark, 'locationNumber'))),
         'This is an agent bookmark',
         'This is not an agent bookmark']
        checkIfReadonlyBookmark = [(bookmark and (type(getattr(bookmark, 'bookmarkID', 0)) == types.TupleType)),
         'This is a readonly bookmark',
         'this is not a readonly bookmark']
        menuEntries = []
        defaultWarpDist = sm.GetService('menu').GetDefaultActionDistance('WarpTo')
        m = []
        if bookmark:
            checkBookmarkWarpTo = [((dist is not None) and ((itemID == eve.session.solarsystemid) or (parentID == eve.session.solarsystemid))),
             mls.UI_MENUHINT_CHECKBOOKMARKWARPTO,
             mls.UI_MENUHINT_CHECKBOOKMARKWARPTONOT]
            checkBookmarkDeadspace = [bool(getattr(bookmark, 'deadspace', 0)),
             mls.UI_MENUHINT_CHECKBOOKMARKDEADSPACE,
             mls.UI_MENUHINT_CHECKBOOKMARKDEADSPACENOT]
            if slimItem:
                menuEntries += [[mls.UI_CMD_SHOWINFO,
                  self.ShowInfo,
                  (slimItem.typeID,
                   slimItem.itemID,
                   0,
                   None,
                   None),
                  (checkMultiSelection, False)], None]
            menuEntries += [[(mls.UI_CMD_APPROACHLOCATION, menu.ACTIONSGROUP),
              self.ApproachLocation,
              (bookmark),
              (checkInSpace,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkApproachDist,
               True),
              'approach'],
             [((mls.UI_CMD_WARPTOLOCATIONWITHIN % {'dist': util.FmtDist(float(defaultWarpDist))}), menu.ACTIONSGROUP),
              self.WarpToBookmark,
              (bookmark, float(defaultWarpDist)),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               False),
              'warp'],
             [(mls.UI_CMD_WARPTOLOCATION, menu.ACTIONSGROUP),
              self.WarpToMenu(self.WarpToBookmark, bookmark),
              None,
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               False),
              'warp'],
             [(mls.UI_CMD_WARPTOLOCATION, menu.ACTIONSGROUP),
              self.WarpToBookmark,
              (bookmark, float(defaultWarpDist)),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               True),
              'warp'],
             [((mls.UI_CMD_WARPFLEETTOLOCATIONWITHIN % {'dist': util.FmtDist(float(defaultWarpDist))}), menu.FLEETGROUP),
              self.WarpToBookmark,
              (bookmark,
               float(defaultWarpDist),
               True),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               False,
               checkFleet,
               True,
               self.CheckImFleetLeader(),
               True),
              'warp'],
             [(mls.UI_CMD_WARPFLEETTOLOCATION, menu.FLEETGROUP),
              self.WarpToBookmark,
              (bookmark,
               float(defaultWarpDist),
               True),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               True,
               checkFleet,
               True,
               self.CheckImFleetLeader(),
               True),
              'warp'],
             [((mls.UI_CMD_WARPWINGTOLOCATIONWITHIN % {'dist': util.FmtDist(float(defaultWarpDist))}), menu.FLEETGROUP),
              self.WarpToBookmark,
              (bookmark,
               float(defaultWarpDist),
               True),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               False,
               checkFleet,
               True,
               self.CheckImWingCmdr(),
               True),
              'warp'],
             [(mls.UI_CMD_WARPWINGTOLOCATION, menu.FLEETGROUP),
              self.WarpToBookmark,
              (bookmark,
               float(defaultWarpDist),
               True),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               True,
               checkFleet,
               True,
               self.CheckImWingCmdr(),
               True),
              'warp'],
             [((mls.UI_CMD_WARPSQUADTOLOCATIONWITHIN % {'dist': util.FmtDist(float(defaultWarpDist))}), menu.FLEETGROUP),
              self.WarpToBookmark,
              (bookmark,
               float(defaultWarpDist),
               True),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               False,
               checkFleet,
               True,
               self.CheckImSquadCmdr(),
               True),
              'warp'],
             [(mls.UI_CMD_WARPSQUADTOLOCATION, menu.FLEETGROUP),
              self.WarpToBookmark,
              (bookmark,
               float(defaultWarpDist),
               True),
              (checkInSpace,
               True,
               checkWarpActive,
               False,
               checkBookmarkWarpTo,
               True,
               checkWarpDist,
               True,
               checkBookmarkDeadspace,
               True,
               checkFleet,
               True,
               self.CheckImSquadCmdr(),
               True),
              'warp'],
             [(mls.UI_CMD_ALIGNTO, menu.ACTIONSGROUP),
              self.AlignToBookmark,
              (getattr(bookmark, 'bookmarkID', None)),
              (checkInSystem,
               True,
               checkMyShip,
               False,
               checkAlignTo,
               True,
               checkWarpActive,
               False,
               checkIfAgentBookmark,
               False),
              'alignto'],
             [(mls.UI_CMD_REMOVELOCATION, menu.CHANGESGROUP),
              sm.GetService('addressbook').DeleteBookmarks,
              ([getattr(bookmark, 'bookmarkID', None)]),
              (checkIfAgentBookmark,
               False,
               checkIfReadonlyBookmark,
               False),
              'deletebookmarks']]
            if (ignoreTypeCheck or (checkStation[0] is True)):
                menuEntries += [None, [mls.UI_CMD_DOCK,
                  self.Dock,
                  (itemID),
                  (checkBP,
                   True,
                   checkInSystem,
                   True,
                   checkStation,
                   True,
                   checkWarpActive,
                   False),
                  mls.UI_CMD_DOCK]]
        elif (bp and (itemID is not None)):
            checkBillboard = [(groupID == const.groupBillboard),
             'This is billboard',
             'This is not billboard']
            checkStructure = [(categoryID in (const.categoryStructure, const.categorySovereigntyStructure)),
             'This item is in category structure',
             'This item is not in category structure']
            checkSovStructure = [(categoryID == const.categorySovereigntyStructure),
             'This item is in category Sov structure',
             'This item is not in category Sov structure']
            checkCapsule = [(groupID == const.groupCapsule),
             'You are in capsule',
             'You are not in capsule']
            checkControlTower = [(groupID == const.groupControlTower),
             'This is a control tower',
             'This is not a control tower']
            checkContainer = [(groupID in (const.groupWreck,
              const.groupCargoContainer,
              const.groupSpawnContainer,
              const.groupSecureCargoContainer,
              const.groupAuditLogSecureContainer,
              const.groupFreightContainer,
              const.groupDeadspaceOverseersBelongings,
              const.groupMissionContainer)),
             'This is container',
             'This is not container']
            checkMyWreck = [((groupID == const.groupWreck) and ((slimItem is not None) and ((slimItem.ownerID == eve.session.charid) or (fleetSvc.IsMember(slimItem.ownerID) or bp.HaveLootRight(slimItem.itemID))))),
             'This is my wreck',
             'This is not my wreck']
            checkMyCargo = [((groupID == const.groupCargoContainer) and ((slimItem is not None) and ((slimItem.ownerID == eve.session.charid) or (fleetSvc.IsMember(slimItem.ownerID) or bp.HaveLootRight(slimItem.itemID))))),
             'This is my cargo',
             'This is not my cargo']
            checkNotAbandoned = [(hasattr(slimItem, 'lootRights') and ((getattr(slimItem, 'lootRights', None) is None) or (None not in getattr(slimItem, 'lootRights', [])))),
             'It is not abandoned',
             'It is abandoned']
            checkCorpHangarArray = [(groupID == const.groupCorporateHangarArray),
             'This is a corp hangar array',
             'This is not a corp hangar array']
            checkAssemblyArray = [(groupID == const.groupAssemblyArray),
             'This is an assembly array',
             'This is not an assembly array']
            checkMobileLaboratory = [(groupID == const.groupMobileLaboratory),
             'This is a mobile laboratory',
             'This is not a mobile laboratory']
            checkRefinery = [(groupID == const.groupRefiningArray),
             'This is refinery',
             'This is not refinery']
            checkSilo = [(groupID == const.groupSilo),
             'This is silo',
             'This is not silo']
            checkConstructionPf = [(groupID in (const.groupConstructionPlatform,
              const.groupStationUpgradePlatform,
              const.groupStationImprovementPlatform)),
             'This is construction platform',
             'This is not construction platform']
            checkJumpPortalArray = [(groupID == const.groupJumpPortalArray),
             'This is a jump portal array',
             'This is not a jump portal array']
            checkPMA = [(groupID in (const.groupPlanet,
              const.groupMoon,
              const.groupAsteroidBelt)),
             badGroup,
             badGroup]
            checkMultiGroups1 = [(groupID in (const.groupSecureCargoContainer,
              const.groupAuditLogSecureContainer,
              const.groupConstructionPlatform,
              const.groupStationUpgradePlatform,
              const.groupStationImprovementPlatform)),
             ('This is %s' % groupName),
             ('This is not %s or %s or %s' % (cfg.invgroups.Get(const.groupSecureCargoContainer).name,
              cfg.invgroups.Get(const.groupConstructionPlatform).name,
              cfg.invgroups.Get(const.groupAuditLogSecureContainer).name))]
            checkMultiGroups2 = [((categoryID == const.categoryDrone) or (groupID == const.groupBiomass)),
             ('This is %s' % groupName),
             ('This is neither %s nor %s' % (cfg.invgroups.Get(const.groupBiomass).name, cfg.invcategories.Get(const.categoryDrone).name))]
            checkAnchorDrop = [godmaSM.TypeHasEffect(typeID, const.effectAnchorDrop),
             'This item can be anchored',
             'This item can not be anchored']
            checkAnchorLift = [godmaSM.TypeHasEffect(typeID, const.effectAnchorLift),
             'This item can be unanchored',
             'This item can not be unanchored']
            checkAutoPilot = [bool(sm.StartService('autoPilot').GetState()),
             mls.UI_MENUHINT_CHECKAUTOPILOT,
             mls.UI_MENUHINT_CHECKAUTOPILOTNOT]
            checkCanRename = [(checkIsMine[0] or (bool((checkIsMyCorps[0] and ((eve.session.corprole & const.corpRoleEquipmentConfig) and (categoryID != const.categorySovereigntyStructure)))) or (eve.session.role & service.ROLE_WORLDMOD))),
             'You can rename this item',
             'You can not rename this item']
            checkAnchorable = [invGroup.anchorable,
             'This item is anchorable',
             'This item is not anchorable']
            checkRenameable = [(not ((groupID == const.groupStation) and (godmaSM.GetType(typeID).isPlayerOwnable == 1))),
             'This type of item can be renamed',
             'This type of item cannot be renamed']
            checkInTargets = [(itemID in sm.StartService('target').GetTargets()),
             mls.UI_MENUHINT_CHECKINTARGETS,
             mls.UI_MENUHINT_CHECKINTARGETSNOT]
            checkBeingTargeted = [sm.StartService('target').BeingTargeted(itemID),
             mls.UI_MENUHINT_CHECKBEINGTARGETED,
             mls.UI_MENUHINT_CHECKBEINGTARGETEDNOT]
            checkAnchorableOrbital = [(util.IsOrbital(categoryID) and invGroup.anchorable),
             'This item can be anchored (orbital)',
             'This item can not be anchored (orbital)']
            checkOnlinableOrbital = [util.IsOrbital(categoryID),
             'This item can be onlined (orbital)',
             'This item can not be onlined (orbital)']
            checkOrbitalOnline = [((slimItem is not None) and (slimItem.orbitalState in (entities.STATE_IDLE, entities.STATE_OPERATING))),
             'This orbital is online',
             'This orbital is not online']
            checkStructureOnline = [((slimItem is not None) and ((slimItem.posState in pos.ONLINE_STABLE_STATES) or ((slimItem.posState == pos.STRUCTURE_ONLINING) and ((slimItem.posTimestamp is None) or ((blue.os.GetTime() - slimItem.posTimestamp) > (sm.StartService('godma').GetTypeAttribute(typeID, const.attributeOnliningDelay) * const.MSEC)))))),
             'This structure is online',
             'This structure is not online']
            scene = sm.GetService('sceneManager').GetRegisteredScene('default')
            camera = sm.GetService('sceneManager').GetRegisteredCamera('default')
            checkResetCamera = [(eve.session.shipid and ((util.GetAttrs(camera, 'parent', 'translationCurve') is None) or ((util.GetAttrs(camera, 'interest') is not None) or (util.GetAttrs(camera, 'parent', 'translationCurve', 'id') == itemID)))),
             mls.UI_MENUHINT_CHECKRESETCAMERA,
             mls.UI_MENUHINT_CHECKRESETCAMERANOT]
            checkScoopable = [((invGroup.anchorable and (otherBall and otherBall.isFree)) or (((shipItem is not None) and ((shipItem.groupID not in (const.groupFreighter, const.groupJumpFreighter)) and ((groupID == const.groupCargoContainer) and ((typeID != const.typeCargoContainer) and (typeID != const.typePlanetaryLaunchContainer))))) or (((shipItem is not None) and ((shipItem.groupID in (const.groupFreighter, const.groupJumpFreighter)) and (groupID == const.groupFreightContainer))) or ((groupID in (const.groupBiomass, const.groupMine)) or (categoryID == const.categoryDrone))))),
             'You can scoop this item',
             'You cannot scoop this kind of item']
            checkScoopableSMA = [((categoryID == const.categoryShip) and ((groupID != const.groupCapsule) and ((not isMyShip) and ((shipItem is not None) and shipItem.hasShipMaintenanceBay)))),
             'You can scoop this ship',
             'You cannot scoop this ship']
            checkKeepRangeGroups = [((categoryID != const.categoryAsteroid) and (groupID not in (const.groupHarvestableCloud,
              const.groupMiningDrone,
              const.groupCargoContainer,
              const.groupSecureCargoContainer,
              const.groupAuditLogSecureContainer,
              const.groupStation,
              const.groupStargate,
              const.groupFreightContainer,
              const.groupWreck))),
             'Correct group',
             (mls.UI_MENU_KEEPINRANGEFALSE % {'groupName': groupName})]
            checkLookingAtItem = [bool((sm.GetService('camera').LookingAt() == itemID)),
             mls.UI_MENUHINT_CHECKLOOKINGATITEM,
             mls.UI_MENUHINT_CHECKLOOKINGATITEMNOT]
            checkInterest = [bool((util.GetAttrs(camera, 'interest', 'translationCurve', 'id') == itemID)),
             'Item is set as interest',
             'Item is not set as interest']
            advancedCamera = [bool(settings.user.ui.Get('advancedCamera', 0)),
             'Advanced camera option is on',
             'Advanced camera option is off']
            checkHasConsumables = [(checkStructure[0] and (godmaSM.GetType(typeID).consumptionType != 0)),
             'This item has a consumable location',
             'This item has no consumable location']
            checkAuditLogSecureContainer = [(groupID == const.groupAuditLogSecureContainer),
             'This is an audit log secure container',
             'This is not an audit log secure container']
            checkShipJumpDrive = [(slimItem and ((shipItem is not None) and shipItem.canJump)),
             'This ship has a jump drive',
             'This ship does not have a jump drive']
            checkShipJumpPortalGenerator = [(slimItem and ((shipItem is not None) and ((shipItem.groupID in [const.groupTitan, const.groupBlackOps]) and (len([ each for each in godmaSM.GetItem(eve.session.shipid).modules if (each.groupID == const.groupJumpPortalGenerator) ]) > 0)))),
             'The ship has a jump portal generator',
             'The ship does not have a jump portal generator']
            checkShipItemHarmonicMatches = [((not isMyShip) and ((categoryID == const.categoryStructure) and sm.services['pwn'].CompareShipStructureHarmonic(eve.session.shipid, itemID))),
             'The ship has a matching harmonic',
             'The ship does not have a matching harmonic']
            checkCorpsOrHarmonicMatches = [(checkIsMyCorps[0] or checkShipItemHarmonicMatches[0]),
             'My corps or harmonic matches',
             'Not my corps and harmonic does not match']
            structureShipBridge = sm.services['pwn'].GetActiveBridgeForShip(itemID)
            checkShipHasBridge = [(structureShipBridge is not None),
             'This ship has an active bridge',
             'This ship does not have an active bridge']
            if (structureShipBridge is not None):
                structureShipBridgeLabel = (mls.UI_CMD_JUMPTHROUGHTOSYSTEM % {'system': cfg.evelocations.Get(structureShipBridge[0]).name})
            else:
                structureShipBridgeLabel = 'ERROR'
            keepRangeranges = [50,
             200,
             500]
            defMenuKeepRangeOptions = [ (util.FmtDist(rnge),
             self.SetDefaultKeepAtRangeDist,
             (rnge)) for rnge in keepRangeranges ]
            keepRangeMenu = [ (util.FmtDist(rnge),
             self.KeepAtRange,
             (itemID, rnge)) for rnge in keepRangeranges ]
            keepRangeMenu += [((mls.UI_CMD_CURRENTRANGE % {'range': niceRange}),
              self.KeepAtRange,
              (itemID, dist)),
             None,
             (mls.UI_CMD_SETDEFAULTRANGE, defMenuKeepRangeOptions)]
            orbitranges = [500,
             1000,
             2500,
             5000,
             7500,
             10000,
             15000,
             20000,
             25000,
             30000]
            defMenuOrbitOptions = [ (util.FmtDist(rnge),
             self.SetDefaultOrbitDist,
             (rnge)) for rnge in orbitranges ]
            orbitMenu = [ (util.FmtDist(rnge),
             self.Orbit,
             (itemID, rnge)) for rnge in orbitranges ]
            orbitMenu += [((mls.UI_CMD_CURRENTRANGE % {'range': niceRange}),
              self.Orbit,
              (itemID, dist)),
             None,
             (mls.UI_CMD_SETDEFAULTRANGE, defMenuOrbitOptions)]
            if checkEnemySpotted[0]:
                (senderID,) = checkEnemySpotted[0]
                menuEntries += [[('%s: Enemy Spotted!' % cfg.eveowners.Get(senderID).name), ('isDynamic',
                   self.CharacterMenu,
                   (senderID))], None]
            if (ignoreTypeCheck or (checkShip[0] is True)):
                checkCanStoreVessel = [((shipItem is not None) and ((slimItem is not None) and ((shipItem.groupID != const.groupCapsule) and (slimItem.itemID != shipItem.itemID)))),
                 'Can store vessel',
                 'Cannot store vessel']
                checkInSameCorp = [(bool(slimItem) and (slimItem.ownerID in sm.StartService('corp').GetMemberIDs())),
                 'You are in the same corporation',
                 'You are not in the same corporation']
                canUseFittingService = [(checkInSameCorp[0] or checkIsMineOrCorpsOrFleets[0]),
                 'You can use fitting service',
                 'You cannot use fitting service']
                menuEntries += [[[mls.UI_CMD_STOPMYSHIP, mls.UI_CMD_STOPMYCAPSULE][(groupID == const.groupCapsule)],
                  self.StopMyShip,
                  None,
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True)],
                 [mls.UI_CMD_OPENMYCARGO,
                  self.OpenCargo,
                  (itemID, 'My'),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True)],
                 [mls.UI_CMD_OPENSHIPMAINTENANCEBAY,
                  self.OpenShipMaintenanceBayShip,
                  (itemID, mls.UI_SHIPMAINTENANCEBAY),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkIfShipMAShip,
                   True)],
                 [mls.UI_CMD_OPENCORPHANGARS,
                  self.OpenShipCorpHangars,
                  (itemID, 'Corporate Hangars'),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkIfShipCHShip,
                   True,
                   checkIsMineOrCorpsOrFleets,
                   True)],
                 [mls.UI_CMD_OPENFUELBAY,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedFuelBay),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipFuelBay,
                   True),
                  'Specialized Fuel Bay'],
                 [mls.UI_CMD_OPENOREHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedOreHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipOreHold,
                   True),
                  'Specialized Ore Hold'],
                 [mls.UI_CMD_OPENGASHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedGasHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipGasHold,
                   True),
                  'Specialized Gas Hold'],
                 [mls.UI_CMD_OPENMINERALHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedMineralHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipMineralHold,
                   True),
                  'Specialized Mineral Hold'],
                 [mls.UI_CMD_OPENSALVAGEHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedSalvageHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipSalvageHold,
                   True),
                  'Specialized Salvage Hold'],
                 [mls.UI_CMD_OPENSHIPHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedShipHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipShipHold,
                   True),
                  'Specialized Ship Hold'],
                 [mls.UI_CMD_OPENSMALLSHIPHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedSmallShipHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipSmallShipHold,
                   True),
                  'Specialized Small Ship Hold'],
                 [mls.UI_CMD_OPENMEDIUMSHIPHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedMediumShipHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipMediumShipHold,
                   True),
                  'Specialized Medium Ship Hold'],
                 [mls.UI_CMD_OPENLARGESHIPHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedLargeShipHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipLargeShipHold,
                   True),
                  'Specialized Large Ship Hold'],
                 [mls.UI_CMD_OPENINDUSTRIALSHIPHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedIndustrialShipHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipIndustrialShipHold,
                   True),
                  'Specialized Industrial Ship Hold'],
                 [mls.UI_CMD_OPENAMMOHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedAmmoHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipAmmoHold,
                   True),
                  'Specialized Ammo Hold'],
                 [mls.UI_CMD_OPENCOMMANDCENTERHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedCommandCenterHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipCommandCenterHold,
                   True),
                  'Specialized Command Center Hold'],
                 [mls.UI_CMD_OPENPLANETARYCOMMODITIESHOLD,
                  self.OpenSpecialCargoBay,
                  (itemID, const.flagSpecializedPlanetaryCommoditiesHold),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkIfShipPlanetaryCommoditiesHold,
                   True),
                  'Specialized Planetary Commodities Hold'],
                 [mls.UI_CMD_STOREVESSEL,
                  self.StoreVessel,
                  (itemID, session.shipid),
                  (checkBP,
                   True,
                   checkConfigDist,
                   True,
                   checkIfShipMAShip,
                   True,
                   checkCanStoreVessel,
                   True,
                   checkIsMineOrCorpsOrFleets,
                   True)],
                 [mls.UI_CMD_CONFIGURESHIP,
                  self.ShipConfig,
                  (itemID),
                  (checkBP,
                   True,
                   checkShipConfig,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkIsMineOrCorpsOrFleets,
                   True)],
                 [mls.UI_CMD_EJECT,
                  self.Eject,
                  None,
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkWarpActive,
                   False),
                  'any'],
                 [mls.UI_CMD_SELFDESTRUCT,
                  self.SelfDestructShip,
                  (itemID),
                  (checkBP,
                   True,
                   checkMyShip,
                   True,
                   checkWarpActive,
                   False),
                  'any'],
                 [mls.UI_CMD_BOARDSHIP,
                  self.Board,
                  (itemID),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   False,
                   checkWarpActive,
                   False,
                   checkShipBusy,
                   False,
                   checkDistNone,
                   False)],
                 [mls.UI_CMD_ENTERSTARBASEPASSWORD,
                  self.EnterPOSPassword,
                  None,
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True),
                  'any'],
                 [mls.UI_CMD_DEACTIVATEAUTOPILOT,
                  self.ToggleAutopilot,
                  (0,),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkAutoPilot,
                   True)],
                 [mls.UI_CMD_ACTIVATEAUTOPILOT,
                  self.ToggleAutopilot,
                  (1,),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkMyShip,
                   True,
                   checkAutoPilot,
                   False),
                  'any'],
                 None,
                 [mls.UI_CMD_JUMPTO,
                  ('isDynamic',
                   self.GetHybridBeaconJumpMenu,
                   []),
                  (checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkShipJumpDrive,
                   True)],
                 [mls.UI_CMD_BRIDGETO,
                  ('isDynamic',
                   self.GetHybridBridgeMenu,
                   []),
                  (checkMyShip,
                   True,
                   checkInCapsule,
                   False,
                   checkShipJumpDrive,
                   True,
                   checkShipJumpPortalGenerator,
                   True)],
                 [(structureShipBridgeLabel, menu.FLEETGROUP),
                  self.JumpThroughAlliance,
                  (itemID),
                  (checkMyShip,
                   False,
                   checkShipHasBridge,
                   True)],
                 None,
                 [mls.UI_CMD_OPENFITTING,
                  uicore.cmd.OpenFitting,
                  (),
                  (checkBP,
                   True,
                   checkShip,
                   True,
                   checkIfShipMAShip,
                   True,
                   canUseFittingService,
                   True)]]
            if (ignoreTypeCheck or (checkPMA[0] is False)):
                checkDrone = [(groupID == const.groupMiningDrone),
                 'This is mining drone',
                 'This is not mining drone']
                menuEntries += [None, [mls.UI_CMD_APPROACH,
                  self.Approach,
                  (itemID, 50),
                  (checkBP,
                   True,
                   checkInSystem,
                   True,
                   checkMyShip,
                   False,
                   checkPMA,
                   False,
                   checkApproachDist,
                   True),
                  'approach']]
                menuEntries += [[mls.UI_CMD_ORBIT,
                  orbitMenu,
                  None,
                  (checkBP,
                   True,
                   checkInSystem,
                   True,
                   checkMyShip,
                   False,
                   checkPMA,
                   False,
                   checkWarpDist,
                   False),
                  mls.UI_CMD_ORBIT]]
                menuEntries += [[mls.UI_CMD_KEEPATRANGE,
                  keepRangeMenu,
                  None,
                  (checkBP,
                   True,
                   checkInSystem,
                   True,
                   checkMyShip,
                   False,
                   checkPMA,
                   False,
                   checkDrone,
                   False,
                   checkKeepRangeGroups,
                   True,
                   checkWarpDist,
                   False),
                  'keepatrange']]
            warpRange = None
            if (checkShip[0] and (slimItem and slimItem.charID)):
                warpFn = self.WarpToMember
                warpFleetFn = self.WarpFleetToMember
                warpID = slimItem.charID
                warpRange = float(defaultWarpDist)
            else:
                warpFn = self.WarpToItem
                warpFleetFn = self.WarpFleet
                warpID = itemID
            menuEntries += [[self.DefaultWarpToLabel(),
              warpFn,
              (warpID, warpRange),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [((mls.UI_CMD_WARPTOWITHIN % {'dist': ''}), menu.ACTIONSGROUP),
              self.WarpToMenu(warpFn, warpID),
              None,
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [mls.UI_CMD_WARPFLEET,
              warpFleetFn,
              (warpID, float(defaultWarpDist)),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkFleet,
               True,
               self.CheckImFleetLeader(),
               True,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [((mls.UI_CMD_WARPFLEETTOWITHIN % {'dist': ''}), menu.FLEETGROUP),
              self.WarpToMenu(warpFleetFn, warpID),
              None,
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkFleet,
               True,
               self.CheckImFleetLeader(),
               True,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [mls.UI_CMD_WARPWING,
              warpFleetFn,
              (warpID, float(defaultWarpDist)),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkFleet,
               True,
               self.CheckImWingCmdr(),
               True,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [(mls.UI_CMD_WARPWINGTOWITHIN % {'dist': ''}),
              self.WarpToMenu(warpFleetFn, warpID),
              None,
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkFleet,
               True,
               self.CheckImWingCmdr(),
               True,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [mls.UI_CMD_WARPSQUAD,
              warpFleetFn,
              (warpID, float(defaultWarpDist)),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkFleet,
               True,
               self.CheckImSquadCmdr(),
               True,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [((mls.UI_CMD_WARPSQUADTOWITHIN % {'dist': ''}), menu.FLEETGROUP),
              self.WarpToMenu(warpFleetFn, warpID),
              None,
              (checkBP,
               True,
               checkInSystem,
               True,
               checkWarpActive,
               False,
               checkFleet,
               True,
               self.CheckImSquadCmdr(),
               True,
               checkMyShip,
               False,
               checkWarpDist,
               True),
              'warp'],
             [self.BroadcastCaption('TARGET'),
              sm.GetService('fleet').SendBroadcast_Target,
              (itemID),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkFleet,
               True,
               checkMyShip,
               False,
               checkApproachDist,
               True),
              'locktarget']]
            menuEntries += [[mls.UI_CMD_ALIGNTO,
              self.AlignTo,
              (itemID),
              (checkInSystem,
               True,
               checkMyShip,
               False,
               checkAlignTo,
               True,
               checkWarpActive,
               False),
              'alignto']]
            menuEntries += [[self.BroadcastCaption('WARPTO'),
              sm.GetService('fleet').SendBroadcast_WarpTo,
              (itemID),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkFleet,
               True,
               checkMultiCategs1,
               False),
              'warp'],
             [self.BroadcastCaption('ALIGNTO'),
              sm.GetService('fleet').SendBroadcast_AlignTo,
              (itemID),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkFleet,
               True,
               checkMultiCategs1,
               False),
              'warp'],
             [self.BroadcastCaption('JUMPTO'),
              sm.GetService('fleet').SendBroadcast_JumpTo,
              (itemID),
              (checkBP,
               True,
               checkInSystem,
               True,
               checkFleet,
               True,
               checkStargate,
               True),
              'warp']]
            if (ignoreTypeCheck or checkJumpThrough[0]):
                throughSystemID = sm.GetService('fleet').CanJumpThrough(slimItem)
                throughSystemName = cfg.evelocations.Get(throughSystemID).name
                menuEntries += [None, [((mls.UI_CMD_JUMPTHROUGHTOSYSTEM % {'system': throughSystemName}), menu.FLEETGROUP),
                  self.JumpThroughFleet,
                  (otherCharID, itemID),
                  (checkBP,
                   True,
                   checkInSystem,
                   True,
                   checkJumpDist,
                   True,
                   checkWarpActive,
                   False),
                  mls.UI_CMD_JUMP]]
            if (ignoreTypeCheck or (checkStation[0] is True)):
                menuEntries += [None, [mls.UI_CMD_DOCK,
                  self.Dock,
                  (itemID),
                  (checkBP,
                   True,
                   checkInSystem,
                   True,
                   checkStation,
                   True,
                   checkWarpActive,
                   False),
                  mls.UI_CMD_DOCK]]
            if (ignoreTypeCheck or (checkStargate[0] is True)):
                dests = []
                locs = []
                for each in slimItem.jumps:
                    if (each.locationID not in locs):
                        locs.append(each.locationID)
                    if (each.toCelestialID not in locs):
                        locs.append(each.toCelestialID)

                if len(locs):
                    cfg.evelocations.Prime(locs)
                for each in slimItem.jumps:
                    solname = cfg.evelocations.Get(each.locationID).name
                    destname = cfg.evelocations.Get(each.toCelestialID).name
                    name = (mls.UI_CMD_DESTNAMEINSYSTEMNAME % {'destination': destname,
                     'system': solname})
                    dests.append((name,
                     self.StargateJump,
                     (itemID,
                      each.toCelestialID,
                      each.locationID)))

                if not dests:
                    dests = [('None', None, None)]
                checkSingleJumpDest = [(len(dests) == 1),
                 mls.UI_MENUHINT_CHECKSINGLEJUMPDEST,
                 mls.UI_MENUHINT_CHECKSINGLEJUMPDESTNOT]
                if dests:
                    checkJumpDest = [(not (not dests)),
                     'There are jump destinations',
                     'There are no jump destinations']
                    menuEntries += [[mls.UI_CMD_JUMP,
                      dests[0][1],
                      dests[0][2],
                      (checkBP,
                       True,
                       checkStargate,
                       True,
                       checkJumpDist,
                       True,
                       checkSingleJumpDest,
                       True,
                       checkCanUseGate,
                       True),
                      mls.UI_CMD_JUMP], [mls.UI_CMD_JUMPTO,
                      dests,
                      None,
                      (checkBP,
                       True,
                       checkStargate,
                       True,
                       checkJumpDist,
                       True,
                       checkSingleJumpDest,
                       False,
                       checkCanUseGate,
                       True),
                      mls.UI_CMD_JUMP]]
                    if dests[0][2]:
                        waypoints = sm.StartService('starmap').GetWaypoints()
                        checkInWaypoints = [(dests[0][2][2] in waypoints),
                         'Solarsystem is already waypoint',
                         'Solarsystem is not in waypoints']
                        menuEntries += [[mls.UI_CMD_ADDFIRSTWAYPOINT,
                          sm.StartService('starmap').SetWaypoint,
                          (dests[0][2][2],
                           0,
                           1),
                          (checkBP,
                           True,
                           checkSingleJumpDest,
                           True,
                           checkStargate,
                           True,
                           checkCanUseGate,
                           True,
                           checkInWaypoints,
                           False),
                          'jump']]
            if (slimItem and (ignoreTypeCheck or (checkWarpgate[0] is True))):
                checkOneTwo = [1,
                 mls.UI_MENUHINT_CHECKONETWO,
                 mls.UI_MENUHINT_CHECKONETWONOT]
                menuEntries += [[mls.UI_CMD_ACTIVATEGATE,
                  self.ActivateAccelerationGate,
                  (itemID),
                  (checkBP,
                   True,
                   checkWarpgate,
                   True,
                   checkOneTwo,
                   True,
                   checkJumpDist,
                   True,
                   checkWarpActive,
                   False)]]
            if (slimItem and (ignoreTypeCheck or (checkWormhole[0] is True))):
                menuEntries += [[mls.UI_CMD_ENTERWORMHOLE,
                  self.EnterWormhole,
                  (itemID),
                  (checkBP,
                   True,
                   checkWormhole,
                   True,
                   checkWormholeDist,
                   True,
                   checkWarpActive,
                   False)]]
            menuEntries += [None,
             [mls.UI_CMD_LOOKAT,
              sm.GetService('camera').LookAt,
              (itemID),
              (checkBP,
               True,
               checkWarpActive,
               False,
               checkLookatDist,
               True,
               checkLookingAtItem,
               False,
               checkPlanet,
               False,
               checkMoon,
               False),
              'lookat'],
             [mls.UI_CMD_SETASPARENT,
              self.SetParent,
              (itemID),
              (checkBP,
               True,
               checkWarpActive,
               False,
               checkLookatDist,
               True,
               checkLookingAtItem,
               False,
               advancedCamera,
               True)],
             [mls.UI_CMD_SETASINTEREST,
              self.SetInterest,
              (itemID),
              (checkBP,
               True,
               checkWarpActive,
               False,
               checkLookatDist,
               True,
               checkInterest,
               False,
               advancedCamera,
               True)],
             [mls.UI_CMD_RESETCAMERA,
              sm.GetService('camera').ResetCamera,
              None,
              (checkBP,
               True,
               checkLookingAtItem,
               True),
              'any']]
            if (ignoreTypeCheck or (checkBillboard[0] is True)):
                newsURL = 'http://www.eveonline.com/mb2/news.asp'
                if (boot.region == 'optic'):
                    newsURL = 'http://eve.gtgame.com.cn/gamenews/index.htm'
                menuEntries += [None, [mls.UI_CMD_READNEWS,
                  uicore.cmd.OpenBrowser,
                  (newsURL, 'browser'),
                  (checkBP,
                   True,
                   checkBillboard,
                   True)]]
            if (ignoreTypeCheck or (checkContainer[0] is True)):
                menuEntries += [None, [mls.UI_CMD_OPENCARGO,
                  self.OpenCargo,
                  [itemID],
                  (checkBP,
                   True,
                   checkTransferDist,
                   True,
                   checkContainer,
                   True)]]
            if (ignoreTypeCheck or (checkPlanetCargoLink[0] is True)):
                menuEntries += [None,
                 [mls.UI_PI_ACCESSCARGOLINK,
                  self.OpenPlanetCargoLinkInventory,
                  [itemID],
                  (checkBP,
                   True,
                   checkPlanetCargoLink,
                   True,
                   checkTransferDist,
                   True)],
                 [mls.UI_PI_CMD_OPENIMEX,
                  self.OpenPlanetCargoLinkImportWindow,
                  [itemID],
                  (checkBP,
                   True,
                   checkPlanetCargoLink,
                   True)]]
            if (ignoreTypeCheck or ((checkMyWreck[0] is True) or (checkMyCargo[0] is True))):
                menuEntries += [[mls.UI_CMD_ABANDONWRECK,
                  self.AbandonLoot,
                  [itemID],
                  (checkBP,
                   True,
                   checkMyWreck,
                   True,
                   checkNotAbandoned,
                   True)],
                 [mls.UI_CMD_ABANDONALLWRECKS,
                  self.AbandonAllLoot,
                  [itemID],
                  (checkBP,
                   True,
                   checkMyWreck,
                   True,
                   checkNotAbandoned,
                   True)],
                 [mls.UI_CMD_ABANDONCARGO,
                  self.AbandonLoot,
                  [itemID],
                  (checkBP,
                   True,
                   checkMyCargo,
                   True,
                   checkNotAbandoned,
                   True)],
                 [mls.UI_CMD_ABANDONALLCARGO,
                  self.AbandonAllLoot,
                  [itemID],
                  (checkBP,
                   True,
                   checkMyCargo,
                   True,
                   checkNotAbandoned,
                   True)]]
            menuEntries += [[mls.UI_CMD_SCOOPTOCARGOHOLD,
              self.Scoop,
              (itemID, typeID),
              (checkBP,
               True,
               checkScoopable,
               True,
               checkTransferDist,
               True)]]
            menuEntries += [[mls.UI_CMD_SCOOPTOMAINTENANCEBAY,
              self.ScoopSMA,
              (itemID),
              (checkBP,
               True,
               checkScoopableSMA,
               True,
               checkTransferDist,
               True)]]
            if (checkConstructionPf[0] is True):
                menuEntries += [None,
                 [mls.UI_CMD_ACCESSRSOURCES,
                  self.OpenConstructionPlatform,
                  (itemID, mls.UI_SHARED_CONSTRUCTIONPLATFORM),
                  (checkBP,
                   True,
                   checkConstructionPf,
                   True,
                   checkTransferDist,
                   True)],
                 [mls.UI_CMD_BUILD,
                  self.BuildConstructionPlatform,
                  (itemID),
                  (checkBP,
                   True,
                   checkConstructionPf,
                   True,
                   checkTransferDist,
                   True)]]
            menuEntries += [[mls.UI_CMD_ANCHOR,
              self.AnchorObject,
              (itemID, 1),
              (checkBP,
               True,
               checkAnchorable,
               True,
               checkConfigDist,
               True,
               checkIsMineOrCorps,
               True,
               checkAnchorDrop,
               True,
               checkIsFree,
               True)],
             [mls.UI_CMD_UNANCHOR,
              self.AnchorObject,
              (itemID, 0),
              (checkBP,
               True,
               checkAnchorable,
               True,
               checkConfigDist,
               True,
               checkIsMineOrCorps,
               True,
               checkAnchorLift,
               True,
               checkIsFree,
               False)],
             [mls.UI_CMD_ANCHOR,
              self.AnchorOrbital,
              (itemID),
              (checkBP,
               True,
               checkAnchorableOrbital,
               True,
               checkConfigDist,
               True,
               checkIsMineOrCorps,
               True,
               checkIsFree,
               True)],
             [mls.UI_CMD_PUTONLINE,
              self.OnlineOrbital,
              (itemID),
              (checkBP,
               True,
               checkConfigDist,
               True,
               checkIsMineOrCorps,
               True,
               checkOnlinableOrbital,
               True,
               checkIsFree,
               False,
               checkOrbitalOnline,
               False)],
             [mls.UI_CMD_UNANCHOR,
              self.UnanchorOrbital,
              (itemID),
              (checkBP,
               True,
               checkAnchorableOrbital,
               True,
               checkConfigDist,
               True,
               checkIsMineOrCorps,
               True,
               checkIsFree,
               False,
               checkOrbitalOnline,
               False)],
             [mls.UI_CMD_PUTOFFLINE,
              self.OfflineOrbital,
              (itemID),
              (checkBP,
               True,
               checkConfigDist,
               True,
               checkIsMineOrCorps,
               True,
               checkOnlinableOrbital,
               True,
               checkIsFree,
               False,
               checkOrbitalOnline,
               True)]]
            structureEntries = []
            if (checkJumpPortalArray[0] is True):
                structureBridge = sm.services['pwn'].GetActiveBridgeForStructure(itemID)
                checkStructureHasBridge = [(structureBridge is not None),
                 'This ship has an active bridge',
                 'This ship does not have an active bridge']
                if (structureBridge is not None):
                    bridgeJumpLabel = (mls.UI_CMD_JUMPTHROUGHTOSYSTEM % {'system': cfg.evelocations.Get(structureBridge[1]).name})
                    bridgeUnlinkLabel = (mls.UI_CMD_UNBRIDGEFROM % {'location': cfg.evelocations.Get(structureBridge[1]).name})
                else:
                    bridgeJumpLabel = 'ERROR'
                    bridgeUnlinkLabel = 'ERROR'
                checkStructureFullyOnline = [sm.services['pwn'].IsStructureFullyOnline(itemID),
                 'The structure is fully online',
                 'The structure is not fully online']
                checkStructureFullyAnchored = [sm.services['pwn'].IsStructureFullyAnchored(itemID),
                 'The structure is fully anchored',
                 'The structure is not fully anchored']
                structureEntries += [[mls.UI_CMD_BRIDGETO,
                  self.JumpPortalBridgeMenu,
                  (itemID),
                  (checkInCapsule,
                   False,
                   checkIsMyCorps,
                   True,
                   checkStructureFullyAnchored,
                   True,
                   checkStructureHasBridge,
                   False)],
                 [bridgeUnlinkLabel,
                  self.UnbridgePortal,
                  (itemID),
                  (checkInCapsule,
                   False,
                   checkIsMyCorps,
                   True,
                   checkStructureHasBridge,
                   True,
                   checkStructureFullyAnchored,
                   True)],
                 [(bridgeJumpLabel, menu.FLEETGROUP),
                  self.JumpThroughPortal,
                  (itemID),
                  (checkInCapsule,
                   False,
                   checkStructureHasBridge,
                   True,
                   checkStructureFullyOnline,
                   True,
                   checkJumpDist,
                   True)],
                 [mls.UI_CMD_ACCESSRSOURCES,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_RESOURCESCONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkIsFree,
                   False,
                   checkTransferDist,
                   True)]]
            if (checkControlTower[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSFUELSTORAGE,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_FUELCONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkControlTower,
                   True,
                   checkIsFree,
                   False)],
                 [mls.UI_CMD_ACCESSTRONTIUMSTORAGE,
                  self.OpenStrontiumBay,
                  (itemID, mls.UI_SHARED_STRONTIUM),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkControlTower,
                   True,
                   checkIsFree,
                   False)],
                 [mls.UI_CMD_MANAGE,
                  self.ManageControlTower,
                  (slimItem),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkIsMineOrCorps,
                   True,
                   checkControlTower,
                   True,
                   checkIsFree,
                   False)],
                 [mls.UI_CMD_SETPASSWORD,
                  self.EnterForceFieldPassword,
                  (itemID),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorps,
                   True,
                   checkControlTower,
                   True,
                   checkIsFree,
                   False)]]
            if (checkSentry[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSAMMUNITION,
                  self.OpenStructureCharges,
                  (itemID,
                   mls.UI_SHARED_AMMUNITIONCONTAINER,
                   True),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkSentry,
                   True,
                   checkIsFree,
                   False)]]
            if (checkLaserSentry[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSACTIVECRYSTAL,
                  self.OpenStructureCharges,
                  (itemID,
                   mls.UI_SHARED_ACTIVECRYSTALCONTAINER,
                   False),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkLaserSentry,
                   True,
                   checkIsFree,
                   False)], [mls.UI_CMD_ACCESSCRYSTALSTORAGE,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_CRYSTALSTORAGECONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkLaserSentry,
                   True,
                   checkIsFree,
                   False)]]
            if (checkHasConsumables[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSRSOURCES,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_RESOURCESCONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkHasConsumables,
                   True,
                   checkIsFree,
                   False)]]
            if (checkShipMaintainer[0] is True):
                checkCanStoreVessel = [((shipItem is not None) and (shipItem.groupID != const.groupCapsule)),
                 'Can store vessel',
                 'Cannot store vessel']
                structureEntries += [[mls.UI_CMD_ACCESSVESSELS,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_SHIPMAINTENANCECONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkTransferDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkShipMaintainer,
                   True,
                   checkIsFree,
                   False)],
                 [mls.UI_CMD_STOREVESSEL,
                  self.StoreVessel,
                  (itemID, session.shipid),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkShipMaintainer,
                   True,
                   checkIsFree,
                   False,
                   checkCanStoreVessel,
                   True)],
                 None,
                 [mls.UI_CMD_OPENFITTING,
                  uicore.cmd.OpenFitting,
                  (),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkShipMaintainer,
                   True,
                   checkIsFree,
                   False)]]
            if (checkCorpHangarArray[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSSTORAGE,
                  self.OpenCorpHangarArray,
                  (itemID, mls.UI_SHARED_CORPHANGARARRAYCONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkTransferDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCorpHangarArray,
                   True,
                   checkIsFree,
                   False,
                   checkStructureOnline,
                   True)]]
            if (checkAssemblyArray[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSSTORAGE,
                  self.OpenCorpHangarArray,
                  (itemID, mls.UI_SHARED_ASSAMBLYARRAYCONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkAssemblyArray,
                   True,
                   checkIsFree,
                   False,
                   checkStructureOnline,
                   True)], [mls.UI_CMD_SETNAME,
                  self.SetName,
                  [slimItem],
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkTransferDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkAssemblyArray,
                   True,
                   checkIsFree,
                   False,
                   checkRenameable,
                   True)]]
            if (checkMobileLaboratory[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSSTORAGE,
                  self.OpenCorpHangarArray,
                  (itemID, mls.UI_SHARED_INDUSTRIALCORPHANGAR),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkMobileLaboratory,
                   True,
                   checkIsFree,
                   False,
                   checkStructureOnline,
                   True)], [mls.UI_CMD_SETNAME,
                  self.SetName,
                  [slimItem],
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkTransferDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkMobileLaboratory,
                   True,
                   checkIsFree,
                   False,
                   checkRenameable,
                   True)]]
            if (checkSilo[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSSTORAGE,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_SILOCONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkTransferDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkSilo,
                   True,
                   checkIsFree,
                   False)]]
            if (checkReactor[0] is True):
                structureEntries += [[mls.UI_CMD_ACCESSSTORAGE,
                  self.OpenStructure,
                  (itemID, mls.UI_SHARED_STRUCTURECONTAINER),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkTransferDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkReactor,
                   True,
                   checkIsFree,
                   False)]]
            if (checkRefinery[0] is True):
                checkRefineryState = [(otherBall and (not otherBall.isFree)),
                 'Refinery available',
                 'Refinery not available']
                structureEntries += [[mls.UI_CMD_ACCESSREFINERY,
                  self.OpenStructureCargo,
                  (itemID, mls.UI_SHARED_PROCESSINGAREACONTAINER),
                  (checkBP,
                   True,
                   checkRefinery,
                   True,
                   checkRefineryState,
                   True,
                   checkTransferDist,
                   True)], [mls.UI_CMD_RUNREFININGPROCESS,
                  self.RunRefiningProcess,
                  (itemID),
                  (checkBP,
                   True,
                   checkRefinery,
                   True,
                   checkTransferDist,
                   True)]]
            if (checkStructure[0] is True):
                checkIsSovereigntyClaimMarker = [((categoryID == const.categorySovereigntyStructure) and (groupID == const.groupSovereigntyClaimMarkers)),
                 'Is a claim Marker',
                 'Not a claim Marker']
                checkIsSovereigntyDisruptor = [((categoryID == const.categorySovereigntyStructure) and (groupID == const.groupSovereigntyDisruptionStructures)),
                 'Is a Stop',
                 'Not a Stop']
                checkCanAnchorStructure = [((not (not slimItem)) and self.pwn.CanAnchorStructure(itemID)),
                 'Can be anchored',
                 'Cannot be anchored']
                checkCanUnanchorStructure = [((not (not slimItem)) and self.pwn.CanUnanchorStructure(itemID)),
                 'Can be unanchored',
                 'Cannot be unanchored']
                checkCanOnlineStructure = [((not (not slimItem)) and self.pwn.CanOnlineStructure(itemID)),
                 'Can be put online',
                 'Cannot be online']
                checkCanOfflineStructure = [((not (not slimItem)) and self.pwn.CanOfflineStructure(itemID)),
                 'Can be put offline',
                 'Cannot be put offline']
                checkCanAssumeControlStructure = [((not (not slimItem)) and self.pwn.CanAssumeControlStructure(itemID)),
                 'Can be controlled',
                 'Cannot be controlled']
                checkHasControlStructureTarget = [((not (not slimItem)) and (self.pwn.GetCurrentTarget(itemID) is not None)),
                 'Can Unlock Target',
                 'Cannot Unlock Target']
                checkHasControl = [((not (not slimItem)) and (slimItem.controllerID is not None)),
                 'Has Control',
                 'Has No Control']
                checkHasMyControl = [((not (not slimItem)) and ((slimItem.controllerID is not None) and (slimItem.controllerID == eve.session.charid))),
                 'Has Your Control',
                 'Has Not Your Control']
                checkIsMineOrCorpsOrAlliancesOrOrphaned = [((not (not slimItem)) and (self.pwn.StructureIsOrphan(itemID) or checkIsMineOrCorpsOrAlliances[0])),
                 'Can be unanchored',
                 'Cannot be unanchored']
                checkIfIAmDirector = [((eve.session.corprole & const.corpRoleDirector) > 0),
                 'You are a Director',
                 'You are not a Director']
                checkInfrastructureHub = [(groupID == const.groupInfrastructureHub),
                 'This is a Infrastructure Hub',
                 'This is not a Infrastructure Hub']
                checkStructureFullyOnline = [self.pwn.IsStructureFullyOnline(itemID),
                 'The structure is fully online',
                 'The structure is not fully online']
                checkInPlanetMode = [sm.GetService('planetUI').IsOpen(),
                 'In planet mode',
                 'Not in planet mode']
                structureEntries += [[mls.UI_CMD_ANCHORSTRUCTURE,
                  sm.StartService('posAnchor').StartAnchorPosSelect,
                  (itemID),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCanAnchorStructure,
                   True,
                   checkStructure,
                   True)],
                 [mls.UI_CMD_UNANCHORSTRUCTURE,
                  self.AnchorStructure,
                  (itemID, 0),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliancesOrOrphaned,
                   True,
                   checkCanUnanchorStructure,
                   True,
                   checkStructure,
                   True)],
                 [mls.UI_CMD_PUTONLINE,
                  self.ToggleObjectOnline,
                  (itemID, 1),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCanOnlineStructure,
                   True,
                   checkStructure,
                   True,
                   checkIsSovereigntyDisruptor,
                   False)],
                 [mls.UI_CMD_PUTOFFLINE,
                  self.ToggleObjectOnline,
                  (itemID, 0),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCanOfflineStructure,
                   True,
                   checkStructure,
                   True)],
                 [mls.UI_CMD_PUTONLINE,
                  self.ToggleObjectOnline,
                  (itemID, 1),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsSovereigntyDisruptor,
                   True,
                   checkCanOnlineStructure,
                   True,
                   checkStructure,
                   True)]]
                structureEntries += [[mls.UI_INFLIGHT_ASSUMECONTROL,
                  self.pwn.AssumeStructureControl,
                  (slimItem),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCanAssumeControlStructure,
                   True,
                   checkCanOfflineStructure,
                   True,
                   checkStructure,
                   True,
                   checkHasControl,
                   False,
                   checkSovStructure,
                   False,
                   checkInPlanetMode,
                   False)], [mls.UI_INFLIGHT_RELINQUISHCONTROL,
                  self.pwn.RelinquishStructureControl,
                  (slimItem),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCanAssumeControlStructure,
                   True,
                   checkCanOfflineStructure,
                   True,
                   checkStructure,
                   True,
                   checkHasMyControl,
                   True,
                   checkSovStructure,
                   False,
                   checkInPlanetMode,
                   False)]]
                structureEntries += [[mls.UI_CMD_UNLOCKSTRUCTURETARGET,
                  self.pwn.UnlockStructureTarget,
                  (itemID),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkIsMineOrCorpsOrAlliances,
                   True,
                   checkCanAssumeControlStructure,
                   True,
                   checkStructure,
                   True,
                   checkHasMyControl,
                   True,
                   checkHasControlStructureTarget,
                   True,
                   checkSovStructure,
                   False)]]
                structureEntries += [[mls.UI_STATION_TRANSFER_OWNERSHIP,
                  self.TransferOwnership,
                  (itemID),
                  (checkBP,
                   True,
                   checkAnchorable,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMyCorps,
                   True,
                   checkCanOfflineStructure,
                   True,
                   checkStructure,
                   True,
                   checkSovStructure,
                   True,
                   checkIfIAmDirector,
                   True,
                   checkIsSovereigntyClaimMarker,
                   True)]]
                structureEntries += [[mls.SOVEREIGNTY_OPEN_HUB_MANAGER,
                  sm.GetService('sov').GetInfrastructureHubWnd,
                  (itemID),
                  (checkBP,
                   True,
                   checkConfigDist,
                   True,
                   checkIsMyCorps,
                   True,
                   checkInfrastructureHub,
                   True,
                   checkStructure,
                   True,
                   checkStructureFullyOnline,
                   True)]]
            if len(structureEntries):
                menuEntries.append(None)
                menuEntries.extend(structureEntries)
            if checkWreck[0]:
                menuEntries += [[mls.UI_CMD_MARKWRECKVIEWED,
                  sm.GetService('wreck').MarkViewed,
                  (itemID, True),
                  (checkWreck,
                   True,
                   checkWreckViewed,
                   False)], [mls.UI_CMD_MARKWRECKNOTVIEWED,
                  sm.GetService('wreck').MarkViewed,
                  (itemID, False),
                  (checkWreck,
                   True,
                   checkWreckViewed,
                   True)]]
            if ((slimItem and ignoreTypeCheck) or (checkMultiGroups2[0] is False)):
                menuEntries += [None, [mls.UI_CMD_SETNAME,
                  self.SetName,
                  [slimItem],
                  (checkBP,
                   True,
                   checkMultiGroups2,
                   False,
                   checkCynoField,
                   False,
                   checkCanRename,
                   True,
                   checkRenameable,
                   True)]]
            tagItemMenu = [(mls.UI_CMD_TAGNUMBER, [ ((' ' + str(i)),
               self.TagItem,
               (itemID, str(i))) for i in xrange(10) ])]
            tagItemMenu += [(mls.UI_CMD_TAGLETTER, [ ((' ' + str(i)),
               self.TagItem,
               (itemID, str(i))) for i in 'ABCDEFGHIJXYZ' ])]
            menuEntries += [None,
             [mls.UI_CMD_UNLOCKTARGET,
              self.UnlockTarget,
              (itemID),
              (checkInTargets,
               True,
               checkBeingTargeted,
               False),
              'unlocktarget'],
             [mls.UI_CMD_LOCKTARGET,
              self.LockTarget,
              (itemID),
              (checkBP,
               True,
               checkMyShip,
               False,
               checkInTargets,
               False,
               checkBeingTargeted,
               False,
               checkPMA,
               False,
               checkTargetingRange,
               True),
              'locktarget'],
             [mls.UI_CMD_TAGITEM,
              tagItemMenu,
              None,
              (checkBP,
               True,
               checkMyShip,
               False,
               checkPMA,
               False,
               checkFleet,
               True,
               checkIfImCommander,
               True)],
             [mls.UI_CMD_STARTCONVERSATION,
              sm.StartService('agents').InteractWith,
              (sm.StartService('godma').GetType(typeID).agentID),
              (checkSpacePig,
               True,
               checkSpacePigDist,
               True)],
             None]
            if (ignoreTypeCheck or (checkMultiGroups1[0] is True)):
                menuEntries += [None,
                 [mls.UI_CMD_SETNEWPASSWORD,
                  self.AskNewContainerPassword,
                  (itemID,
                   mls.UI_GENERIC_SETPASSWORDONSECURECONT,
                   const.SCCPasswordTypeGeneral),
                  (checkBP,
                   True,
                   checkMultiGroups1,
                   True)],
                 [mls.UI_CMD_SETNEWCONFIGURATIONPASSWORD,
                  self.AskNewContainerPassword,
                  (itemID,
                   mls.UI_GENERIC_SETCONFIGPASSWORDONSECURECONT,
                   const.SCCPasswordTypeConfig),
                  (checkBP,
                   True,
                   checkAuditLogSecureContainer,
                   True)],
                 [mls.UI_CMD_VIEWLOG,
                  self.ViewAuditLogForALSC,
                  (itemID),
                  (checkBP,
                   True,
                   checkAuditLogSecureContainer,
                   True,
                   checkIsMineOrCorps,
                   True)],
                 [mls.UI_CMD_CONFIGURECONTAINER,
                  self.ConfigureALSC,
                  (itemID),
                  (checkBP,
                   True,
                   checkAuditLogSecureContainer,
                   True,
                   checkIsMineOrCorps,
                   True)],
                 [mls.UI_CMD_RETRIEVEPASSWORD,
                  self.RetrievePasswordALSC,
                  (itemID),
                  (checkBP,
                   True,
                   checkAuditLogSecureContainer,
                   True,
                   checkIsMineOrCorps,
                   True)]]
        checkInTactical = [sm.StartService('tactical').CheckIfGroupIDActive(groupID),
         'Item is in tactical view',
         'Item is not in tactical view']
        mapTypeID = typeID
        mapFunctionID = None
        if ((groupID in [const.groupSolarSystem,
         const.groupConstellation,
         const.groupRegion]) and ((parentID != eve.session.solarsystemid) and (not (bookmark and ((bookmark.itemID == bookmark.locationID) and (bookmark.x and (bookmark.y and bookmark.z))))))):
            mapFunctionID = (mapItemID or itemID)
        elif bookmark:
            mapFunctionID = bookmark.locationID
            parentBookmarkItem = sm.StartService('map').GetItem(mapFunctionID)
            if (parentBookmarkItem and (parentBookmarkItem.groupID == const.groupSolarSystem)):
                mapTypeID = parentBookmarkItem.typeID
        elif parentID:
            parentMapItem = sm.StartService('map').GetItem(parentID)
            if (parentMapItem and (parentMapItem.groupID == const.groupSolarSystem)):
                mapFunctionID = parentID
                mapTypeID = parentMapItem.typeID
        else:
            if (groupID == const.groupStation):
                if itemID:
                    parentID = sm.StartService('ui').GetStation(itemID).solarSystemID
                    if (parentID != eve.session.solarsystemid):
                        mapTypeID = const.typeSolarSystem
                        mapFunctionID = parentID
        checkSameSolarSystemID = [(mapFunctionID and (mapFunctionID == eve.session.solarsystemid2)),
         'same solarsystem',
         'not same solarsystemid']
        checkHaveSolarSystemID = [(mapTypeID == const.typeSolarSystem),
         'This is solarsystem',
         'This is not solarsystem']
        if (checkHaveSolarSystemID[0] is True):
            waypoints = sm.StartService('starmap').GetWaypoints()
            checkInWaypoints = [(mapFunctionID in waypoints),
             'Solarsystem is already waypoint',
             'Solarsystem is not in waypoints']
            menuEntries += [None,
             [mls.UI_CMD_SETDESTINATION,
              sm.StartService('starmap').SetWaypoint,
              (mapFunctionID, 1),
              (checkHaveSolarSystemID,
               True,
               checkSameSolarSystemID,
               False)],
             [mls.UI_CMD_REMOVEWAYPOINT,
              sm.StartService('starmap').ClearWaypoints,
              (mapFunctionID),
              (checkHaveSolarSystemID,
               True,
               checkInWaypoints,
               True)],
             [mls.UI_CMD_ADDWAYPOINT,
              sm.StartService('starmap').SetWaypoint,
              (mapFunctionID),
              (checkHaveSolarSystemID,
               True,
               checkInWaypoints,
               False)]]
            if checkFleet[0]:
                menuEntries += [None, [self.BroadcastCaption('TRAVELTO'),
                  sm.GetService('fleet').SendBroadcast_TravelTo,
                  (mapFunctionID),
                  (checkHaveSolarSystemID,
                   True,
                   checkFleet,
                   True,
                   checkSolarSystem,
                   True)]]
        elif (checkStation[0] and ((parentID is not None) and (parentID != session.solarsystemid2))):
            menuEntries += [None, [mls.UI_CMD_SETDESTINATION,
              sm.StartService('starmap').SetWaypoint,
              (parentID, 1),
              ()]]
        if session.solarsystemid:
            menuEntries += [[((mls.UI_CMD_ADDTOOVERVIEW % {'item': groupName}), menu.NAVIGATIONGROUP2),
              sm.StartService('tactical').ChangeSettings,
              ('groups',
               groupID,
               1),
              (checkInTactical,
               False,
               checkIfLandmark,
               False),
              'any'], [((mls.UI_CMD_REMOVEFROMOVERVIEW % {'item': groupName}), menu.CHANGESGROUP),
              sm.StartService('tactical').ChangeSettings,
              ('groups',
               groupID,
               0),
              (checkInTactical,
               True,
               checkIfLandmark,
               False),
              'any']]
        if ((not bookmark) and (checkMultiCategs1[0] is False)):
            if (groupID == const.groupBeacon):
                beacon = sm.StartService('michelle').GetItem(itemID)
                if beacon:
                    if (hasattr(beacon, 'dunDescription') and beacon.dunDescription):
                        hint = beacon.dunDescription
                if itemID:
                    if parentID:
                        menuEntries += [None, [mls.UI_CMD_BOOKMARKLOCATION,
                          self.Bookmark,
                          (itemID,
                           typeID,
                           parentID,
                           hint),
                          (checkMultiCategs1,
                           False,
                           checkIfLandmark,
                           False),
                          'bookmark']]
                if ((ignoreTypeCheck or (mapFunctionID is not None)) and (groupID in [const.groupSolarSystem,
                 const.groupConstellation,
                 const.groupRegion])):
                    checkMultiGroups3 = [(mapFunctionID is not None),
                     ('This is %s' % groupName),
                     ('This is not %s, %s nor %s' % (cfg.invgroups.Get(const.groupRegion).name,
                      cfg.invgroups.Get(const.groupConstellation).name,
                      cfg.invgroups.Get(const.groupSolarSystem).name))]
                    menuEntries += [None,
                     [mls.UI_CMD_SHOWONMAP,
                      self.ShowInMap,
                      (mapFunctionID),
                      (checkMultiGroups3, True)],
                     [((mls.UI_CMD_SHOWITEMONMAPBROWSER % {'item': groupName}), menu.NAVIGATIONGROUP2),
                      self.ShowInMapBrowser,
                      (mapFunctionID),
                      (checkMultiGroups3, True)]]
                    if (mapFunctionID not in sm.StartService('pathfinder').GetAvoidanceItems()):
                        menuEntries.append([((mls.UI_CMD_AVOIDITEM % {'item': groupName}), menu.NAVIGATIONGROUP2),
                         sm.StartService('pathfinder').AddAvoidanceItem,
                         (mapFunctionID),
                         (checkMultiGroups3, True)])
                    else:
                        menuEntries.append([((mls.UI_CMD_STOPAVOIDITEM % {'item': groupName}), menu.NAVIGATIONGROUP2),
                         sm.StartService('pathfinder').RemoveAvoidanceItem,
                         (mapFunctionID),
                         (checkMultiGroups3, True)])
            if session.solarsystemid:
                menuEntries += [[((mls.UI_CMD_ADDTOOVERVIEW % {'item': groupName}), menu.NAVIGATIONGROUP2),
                  sm.StartService('tactical').ChangeSettings,
                  ('groups',
                   groupID,
                   1),
                  (checkInTactical,
                   False,
                   checkIfLandmark,
                   False),
                  'any'], [((mls.UI_CMD_REMOVEFROMOVERVIEW % {'item': groupName}), menu.CHANGESGROUP),
                  sm.StartService('tactical').ChangeSettings,
                  ('groups',
                   groupID,
                   0),
                  (checkInTactical,
                   True,
                   checkIfLandmark,
                   False),
                  'any']]
            if (checkPlanet[0] and (itemID is not None)):
                menuEntries += [[mls.UI_PI_VIEW_IN_PLANET_MODE,
                  sm.GetService('planetUI').Open,
                  (itemID),
                  (checkPlanet,
                   True,
                   checkThisPlanetOpen,
                   False),
                  'any'], [mls.UI_PI_EXIT_PLANET_MODE,
                  sm.GetService('planetUI').Close,
                  (),
                  (checkPlanet,
                   True,
                   checkThisPlanetOpen,
                   True),
                  'any']]
            if ((not ignoreDroneMenu) and (slimItem and (categoryID == const.categoryDrone))):
                newMenuEntries = [None]
                for me in self.DroneMenu([[itemID,
                  groupID,
                  slimItem.ownerID]], showInactive, 1):
                    newMenuEntries.extend(me)

                newMenuEntries.extend(menuEntries)
                menuEntries = newMenuEntries
            if not (filterFunc and (mls.UI_CMD_SHOWINFO in filterFunc)):
                menuEntries += [[mls.UI_CMD_SHOWINFO,
                  self.ShowInfo,
                  (typeID,
                   itemID,
                   0,
                   None,
                   parentID),
                  (checkMultiSelection, False)]]
            m += self.ParseMenu(menuEntries, showInactive, filterFunc)
            if (groupID == const.groupPlanet):
                moons = self.GetPrimedMoons(itemID)
                if moons:
                    m.append((mls.UI_CMD_MOONS, ('isDynamic',
                      self.GetMoons,
                      (itemID, moons))))
                if (checkBP[0] and checkInSystem[0]):
                    cargoLinkIDs = bp.GetCargoLinksForPlanet(itemID)
                    if ((cargoLinkIDs is not None) and (len(cargoLinkIDs) > 0)):
                        cargoLinkID = cargoLinkIDs[0]
                        cargoLinkBall = bp.GetBall(cargoLinkID)
                        if cargoLinkBall:
                            m.append((mls.UI_PI_CMD_CUSTOMSOFFICE, ('isDynamic',
                              self.GetCargoLinkMenu,
                              (cargoLinkID))))
            if ((checkShip[0] is True) and slimItem):
                m += ([None] + [(mls.UI_CMD_PILOT, ('isDynamic',
                   self.CharacterMenu,
                   ((slimItem.charID or slimItem.ownerID),
                    [],
                    slimItem.corpID,
                    0,
                    0,
                    [mls.UI_CMD_GMEXTRAS])))])
            if ((not (filterFunc and (mls.UI_CMD_VIEWMARKETDETAILS in filterFunc))) and checkHasMarketGroup[0]):
                m += [(mls.UI_CMD_VIEWMARKETDETAILS,
                  self.ShowMarketDetails,
                  (util.KeyVal(typeID=typeID)))]
            if ((not (filterFunc and (mls.UI_CMD_FINDINCONTRACTS in filterFunc))) and (checkIsPublished[0] and (not ignoreMarketDetails))):
                m += [(mls.UI_CMD_FINDINCONTRACTS,
                  sm.GetService('contracts').FindRelated,
                  (typeID,
                   None,
                   None,
                   None,
                   None,
                   None))]
            if ((not (filterFunc and (mls.UI_CMD_GMEXTRAS in filterFunc))) and (eve.session.role & (service.ROLE_GML | service.ROLE_WORLDMOD))):
                m = ([(mls.UI_CMD_GMEXTRAS, ('isDynamic',
                   self.GetGMMenu,
                   (itemID,
                    slimItem,
                    None,
                    None,
                    mapItem)))] + m)
            return m



    def BroadcastCaption(self, which):
        return ('%s: %s' % (mls.UI_FLEET_BROADCAST, getattr(mls, ('UI_FLEET_BROADCAST_%s' % which.upper()))))



    def JumpPortalBridgeMenu(self, itemID):
        l = []
        fromSystem = cfg.evelocations.Get(session.solarsystemid)
        for (solarSystemID, structureID,) in sm.RemoteSvc('map').GetLinkableJumpArrays():
            if (solarSystemID == session.solarsystemid):
                continue
            toSystem = cfg.evelocations.Get(solarSystemID)
            dist = uix.GetLightYearDistance(fromSystem, toSystem)
            l.append((('%s<t>%.1f ly' % (toSystem.name, dist)), (solarSystemID, structureID)))

        pick = uix.ListWnd(l, 'generic', mls.UI_SHARED_PICKDESTINATION, isModal=1, scrollHeaders=[mls.UI_GENERIC_SOLARSYSTEM, mls.UI_GENERIC_DISTANCE])
        if pick:
            (remoteSolarSystemID, remoteItemID,) = pick[1]
            self.BridgePortals(itemID, remoteSolarSystemID, remoteItemID)



    def BridgePortals(self, localItemID, remoteSolarSystemID, remoteItemID):
        posLocation = util.Moniker('posMgr', session.solarsystemid)
        posLocation.InstallJumpBridgeLink(localItemID, remoteSolarSystemID, remoteItemID)



    def UnbridgePortal(self, itemID):
        posLocation = util.Moniker('posMgr', session.solarsystemid)
        posLocation.UninstallJumpBridgeLink(itemID)



    def JumpThroughPortal(self, itemID):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        slim = sm.services['michelle'].GetItem(itemID)
        remoteStructureID = slim.remoteStructureID
        if not remoteStructureID:
            return 
        remoteSystemID = slim.remoteSystemID
        self.LogNotice('Jump Through Portal', itemID, remoteStructureID, remoteSystemID)
        sm.StartService('sessionMgr').PerformSessionChange('jump', bp.JumpThroughCorporationStructure, itemID, remoteStructureID, remoteSystemID)



    def GetFuelConsumptionOfJumpBridgeForMyShip(self, fromSystem, toSystem, toStructureType):
        if not eve.session.shipid:
            return 
        else:
            myShip = sm.services['godma'].GetItem(eve.session.shipid)
            if (myShip is None):
                return 
            myDist = uix.GetLightYearDistance(fromSystem, toSystem, False)
            if (myDist is None):
                return 
            attrDict = sm.GetService('info').GetAttrDict(toStructureType)
            attrs = [const.attributeJumpDriveConsumptionAmount, const.attributeJumpPortalConsumptionMassFactor]
            for each in attrs:
                if attrDict.has_key(each):
                    myDist *= attrDict[each]

            shipMass = getattr(myShip, 'mass', None)
            if shipMass:
                myDist *= shipMass
            return (myDist, attrDict.get(const.attributeJumpDriveConsumptionType, None))



    def GetFuelConsumptionForMyShip(self, fromSystem, toSystem, attrDict):
        if not eve.session.shipid:
            return 
        else:
            myDist = uix.GetLightYearDistance(fromSystem, toSystem, False)
            if (myDist is None):
                return 
            if (len(attrDict) > 0):
                for displayAttribute in attrDict:
                    if (displayAttribute.attributeID == const.attributeJumpDriveConsumptionAmount):
                        consumptionAmount = (myDist * displayAttribute.value)
                    else:
                        comsumptionType = displayAttribute.value

                return (int(consumptionAmount), comsumptionType)
            return (None, None)



    def GetHybridBeaconJumpMenu(self):
        m = []
        fleetMenu = []
        allianceMenu = []
        if session.fleetid:
            beacons = sm.GetService('fleet').GetActiveBeacons()
            for (charID, beaconArgs,) in beacons.iteritems():
                (solarSystemID, itemID,) = beaconArgs
                if (solarSystemID != session.solarsystemid):
                    solarsystem = cfg.evelocations.Get(solarSystemID)
                    character = cfg.eveowners.Get(charID)
                    charName = ('%s (%s)' % (character.name, solarsystem.name))
                    fleetMenu.append((uiutil.UpperCase(character.name), (charID,
                      beaconArgs,
                      charName)))

            fleetMenu = uiutil.SortListOfTuples(fleetMenu)
        if session.allianceid:
            beacons = sm.RemoteSvc('map').GetAllianceBeacons()
            for (solarSystemID, structureID, structureTypeID,) in beacons:
                if (solarSystemID != session.solarsystemid):
                    solarsystem = cfg.evelocations.Get(solarSystemID)
                    invType = cfg.invtypes.Get(structureTypeID)
                    structureName = ('%s (%s)' % (solarsystem.name, invType.Group().name))
                    allianceMenu.append((uiutil.UpperCase(solarsystem.name), (solarSystemID,
                      structureID,
                      structureName)))

            allianceMenu = uiutil.SortListOfTuples(allianceMenu)
        fullMenu = []
        if (len(fleetMenu) > 0):
            for (charID, beaconArgs, charName,) in fleetMenu:
                fullMenu.append([charName,
                 self.JumpToBeaconFleet,
                 (charID, beaconArgs)])

        if (len(allianceMenu) > 0):
            if (len(fullMenu) > 0):
                fullMenu.append(None)
            for (solarSystemID, structureID, structureName,) in allianceMenu:
                fullMenu.append([structureName,
                 self.JumpToBeaconAlliance,
                 (solarSystemID, structureID)])

        if (len(fullMenu) > 0):
            if (len(fullMenu) > 40):
                return ([mls.UI_CMD_OPENCAPITALNAVIGATION, self.OpenCapitalNavigation])
            else:
                return fullMenu
        else:
            return ([mls.UI_GENERIC_NODESTINATION, self.DoNothing])



    def OpenCapitalNavigation(self, *args):
        if session.shipid:
            wnd = sm.GetService('window').GetWindow('capitalnav', decoClass=form.CapitalNav, create=1, maximize=1)



    def GetHybridBridgeMenu(self):
        m = []
        fleetMenu = []
        allianceMenu = []
        menuSize = 20
        if session.fleetid:
            menu = []
            beacons = sm.GetService('fleet').GetActiveBeacons()
            for (charID, beaconArgs,) in beacons.iteritems():
                (solarSystemID, itemID,) = beaconArgs
                if (solarSystemID != session.solarsystemid):
                    solarsystem = cfg.evelocations.Get(solarSystemID)
                    character = cfg.eveowners.Get(charID)
                    charName = ('%s (%s)' % (character.name, solarsystem.name))
                    menu.append((uiutil.UpperCase(character.name), (charID,
                      beaconArgs,
                      charName)))

            menu = uiutil.SortListOfTuples(menu)
            fleetMenu = [ (charName,
             self.BridgeToBeacon,
             (charID, beaconArgs)) for (charID, beaconArgs, charName,) in menu ]
        if session.allianceid:
            menu = []
            datas = sm.RemoteSvc('map').GetAllianceBeacons()
            for (solarSystemID, structureID, structureTypeID,) in datas:
                if (solarSystemID != session.solarsystemid):
                    solarsystem = cfg.evelocations.Get(solarSystemID)
                    invtype = cfg.invtypes.Get(structureTypeID)
                    structureName = ('%s (%s)' % (solarsystem.name, invtype.Group().name))
                    menu.append((uiutil.UpperCase(solarsystem.name), (solarSystemID,
                      structureID,
                      structureName)))

            menu = uiutil.SortListOfTuples(menu)
            all = []
            while (len(menu) > menuSize):
                all.append(menu[:menuSize])
                menu = menu[menuSize:]

            if menu:
                all.append(menu)
            if not all:
                allianceMenu = all
            if (len(all) == 1):
                allianceMenu = self.GetAllianceBeaconSubMenu(all[0], self.BridgeToBeaconAlliance)
            else:
                allianceMenu = [ (('%c ... %c' % (sub[0][2][0], sub[-1][2][0])), ('isDynamic',
                  self.GetAllianceBeaconSubMenu,
                  (sub, self.BridgeToBeaconAlliance))) for sub in all ]
        if ((len(fleetMenu) > 0) and (len(allianceMenu) > 0)):
            fleetMenu.append(None)
        fleetMenu.extend(allianceMenu)
        if (len(fleetMenu) == 0):
            return ([mls.UI_GENERIC_NODESTINATION, self.DoNothing])
        else:
            return fleetMenu



    def GetAllianceBeaconSubMenu(self, structureIDs, func):
        return [ [structureName,
         func,
         (solarSystemID, structureID)] for (solarSystemID, structureID, structureName,) in structureIDs ]



    def RigSlotMenu(self, itemID):
        menu = []
        if (itemID == eve.session.shipid):
            ship = sm.GetService('godma').GetItem(eve.session.shipid)
            for module in ship.modules:
                rigslots = [ getattr(const, ('flagRigSlot%s' % i), None) for i in xrange(8) ]
                if (module.flagID in rigslots):
                    menu.append([(module.name + (' (Slot %s)' % rigslots.index(module.flagID))),
                     [(mls.UI_CMD_SHOWINFO,
                       self.ShowInfo,
                       (module.typeID, module.itemID))],
                     None,
                     ()])

        if not menu:
            return []
        else:
            return [(mls.UI_GENERIC_RIGS,
              menu,
              None,
              ())]



    def RemoveRig(self, moduleID, shipID):
        if eve.session.stationid:
            eve.GetInventory(const.containerHangar).Add(moduleID, shipID)



    def RigFittingCheck(self, invItem):
        moduleEffects = cfg.dgmtypeeffects.get(invItem.typeID, [])
        for mEff in moduleEffects:
            if (mEff.effectID == const.effectRigSlot):
                if (eve.Message('RigFittingInfo', {}, uix.OKCANCEL) != uix.ID_OK):
                    return 0

        return 1



    def ConfirmMenu(self, func):
        m = [(mls.UI_GENERIC_CONFIRM, func)]
        return m



    def WarpToMenu(self, func, ID):
        ranges = [const.minWarpEndDistance,
         (((const.minWarpEndDistance / 10000) + 1) * 10000),
         (((const.minWarpEndDistance / 10000) + 2) * 10000),
         (((const.minWarpEndDistance / 10000) + 3) * 10000),
         (((const.minWarpEndDistance / 10000) + 5) * 10000),
         (((const.minWarpEndDistance / 10000) + 7) * 10000),
         const.maxWarpEndDistance]
        defaultWarpDist = sm.GetService('menu').GetDefaultActionDistance('WarpTo')
        defMenuWarpOptions = [ (util.FmtDist(rnge),
         self.SetDefaultWarpToDist,
         (rnge)) for rnge in ranges ]
        warpDistMenu = [((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[0])}),
          func,
          (ID, float(ranges[0]))),
         ((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[1])}),
          func,
          (ID, float(ranges[1]))),
         ((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[2])}),
          func,
          (ID, float(ranges[2]))),
         ((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[3])}),
          func,
          (ID, float(ranges[3]))),
         ((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[4])}),
          func,
          (ID, float(ranges[4]))),
         ((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[5])}),
          func,
          (ID, float(ranges[5]))),
         ((mls.UI_CMD_WARPTOSUBMENU % {'dist': util.FmtDist(ranges[6])}),
          func,
          (ID, float(ranges[6]))),
         None,
         (mls.UI_CMD_SETDEFAULTRANGE, defMenuWarpOptions)]
        return warpDistMenu



    def MergeMenus(self, menus):
        if not menus:
            return []
        else:
            typeDict = {}
            allCaptions = []
            for menu in menus:
                i = 0
                for each in menu:
                    if (each is None):
                        if (len(allCaptions) <= i):
                            allCaptions.append(None)
                        else:
                            while (allCaptions[i] != None):
                                i += 1
                                if (i == len(allCaptions)):
                                    allCaptions.append(None)
                                    break

                    elif (each[0] not in allCaptions):
                        allCaptions.insert(i, each[0])
                        typeDict[each[0]] = type(each[1])
                    i += 1


            menus = filter(None, [ filter(None, each) for each in menus ])
            for caption in allCaptions:
                if (caption is None):
                    continue
                for menu in menus:
                    ok = 0
                    for menuEntry in menu:
                        if (menuEntry[0] not in typeDict):
                            continue
                        if (menuEntry[0] == caption):
                            if (type(menuEntry[1]) == typeDict[caption]):
                                ok = 1
                                break
                    else:
                        ok = 1

                    if ((not ok) and (caption in typeDict)):
                        del typeDict[caption]


            for caption in self.bypassCommonFilter:
                if (caption not in allCaptions):
                    allCaptions.append(caption)

            ret = []
            menulen = len(menus)
            for caption in allCaptions:
                if (caption is None):
                    ret.append(None)
                    continue
                if ((caption not in typeDict) and (caption not in self.bypassCommonFilter)):
                    continue
                lst = []
                isList = None
                broken = 0
                for menu in menus:
                    for entry in menu:
                        if (entry[0] == caption):
                            if (type(entry[1]) in (str, unicode)):
                                if (caption in self.bypassCommonFilter):
                                    pass
                            ret.append((caption, entry[1]))
                            broken = 1
                            break
                        if ((type(entry[1]) == tuple) and ((entry[1][0] == 'isDynamic') and (len(entry) == 2))):
                            ret.append((caption, entry[1]))
                            broken = 1
                            break
                        if (isList is None):
                            isList = (type(entry[1]) == list)
                        if (isList != (type(entry[1]) == list)):
                            broken = 1
                        elif isList:
                            lst.append(entry[1])
                        else:
                            lst.append(entry[1:])
                        break
                        continue

                    if broken:
                        break

                if broken:
                    continue
                if isList:
                    ret.append((caption, self.MergeMenus(lst)))
                elif ((caption in self.multiFunctions) or (len(lst) and (len(lst[0]) and (lst[0][0] in self.multiFunctionFunctions)))):
                    mergedArgs = []
                    for (_func, args,) in lst:
                        if (type(args) == type([])):
                            mergedArgs += args
                        else:
                            uix.LogWarn('unsupported format of arguments for MergeMenu, function label: ', caption)

                    if mergedArgs:
                        if ((type(lst[0][0]) == tuple) and (lst[0][0][0] == 'isDynamic')):
                            ret.append((caption, (lst[0][0][0],
                              lst[0][0][1],
                              (lst[0][0][2] + (mergedArgs)))))
                        else:
                            ret.append((caption,
                             self.CheckLocked,
                             (lst[0][0], mergedArgs)))
                else:
                    ret.append((caption,
                     self.ExecMulti,
                     lst))
                    continue

            return ret



    def ExecMulti(self, *actions):
        for each in actions:
            uthread.new(self.ExecAction, each)




    def ExecAction(self, action):
        apply(*action)



    def GetMenuFormItemIDTypeID(self, itemID, typeID, bookmark = None, filterFunc = None, invItem = None, ignoreMarketDetails = 1):
        if (typeID is None):
            return []
        else:
            if invItem:
                return self.InvItemMenu(invItem, filterFunc=filterFunc)
            typeinfo = cfg.invtypes.Get(typeID)
            groupinfo = typeinfo.Group()
            if (typeinfo.groupID in (const.groupCharacter)):
                return self.CharacterMenu(itemID, filterFunc=filterFunc)
            if (groupinfo.categoryID in (const.categoryCelestial,
             const.categoryStructure,
             const.categoryStation,
             const.categoryShip,
             const.categoryEntity,
             const.categoryDrone,
             const.categoryAsteroid)):
                return self.CelestialMenu(itemID, typeID=typeID, bookmark=bookmark, filterFunc=filterFunc, ignoreMarketDetails=ignoreMarketDetails)
            m = []
            if not (filterFunc and (mls.UI_CMD_SHOWINFO in filterFunc)):
                m += [(mls.UI_CMD_SHOWINFO,
                  self.ShowInfo,
                  (typeID,
                   itemID,
                   0,
                   None,
                   None))]
            if ((typeinfo.groupID == const.groupCorporation) and (util.IsCorporation(itemID) and (not util.IsNPC(itemID)))):
                m += [(mls.UI_CMD_GIVEMONEY,
                  sm.StartService('wallet').TransferMoney,
                  (eve.session.charid,
                   None,
                   itemID,
                   None))]
            if (typeinfo.groupID in [const.groupCorporation,
             const.groupAlliance,
             const.groupFaction]):
                addressBookSvc = sm.GetService('addressbook')
                inAddressbook = addressBookSvc.IsInAddressBook(itemID, 'contact')
                isBlocked = addressBookSvc.IsBlocked(itemID)
                isNPC = util.IsNPC(itemID)
                if inAddressbook:
                    m += ((mls.UI_CONTACTS_EDITCONTACT,
                      addressBookSvc.AddToPersonalMulti,
                      [itemID,
                       'contact',
                       True]))
                    m += ((mls.UI_CONTACTS_REMOVEFROMCONTACTS,
                      addressBookSvc.DeleteEntryMulti,
                      [[itemID], 'contact']))
                else:
                    m += ((mls.UI_CONTACTS_ADDTOCONTACTS,
                      addressBookSvc.AddToPersonalMulti,
                      [itemID, 'contact']))
                if not isNPC:
                    if isBlocked:
                        m += ((mls.UI_CMD_UNBLOCK,
                          addressBookSvc.UnblockOwner,
                          [[itemID]]))
                    else:
                        m += ((mls.UI_CMD_BLOCK,
                          addressBookSvc.BlockOwner,
                          [itemID]))
                iAmDiplomat = (((const.corpRoleDirector | const.corpRoleDiplomat) & session.corprole) != 0)
                if iAmDiplomat:
                    inCorpAddressbook = addressBookSvc.IsInAddressBook(itemID, 'corpcontact')
                    if inCorpAddressbook:
                        m += ((mls.UI_CONTACTS_EDITCORPCONTACT,
                          addressBookSvc.AddToPersonalMulti,
                          [itemID,
                           'corpcontact',
                           True]))
                        m += ((mls.UI_CONTACTS_REMOVECORPCONTACT,
                          addressBookSvc.DeleteEntryMulti,
                          [[itemID], 'corpcontact']))
                    else:
                        m += ((mls.UI_CONTACTS_ADDCORPCONTACT,
                          addressBookSvc.AddToPersonalMulti,
                          [itemID, 'corpcontact']))
                    if session.allianceid:
                        execCorp = (sm.GetService('alliance').GetAlliance(session.allianceid).executorCorpID == session.corpid)
                        if execCorp:
                            inAllianceAddressbook = addressBookSvc.IsInAddressBook(itemID, 'alliancecontact')
                            if inAllianceAddressbook:
                                m += ((mls.UI_CONTACTS_EDITALLIANCECONTACT,
                                  addressBookSvc.AddToPersonalMulti,
                                  [itemID,
                                   'alliancecontact',
                                   True]))
                                m += ((mls.UI_CONTACTS_REMOVEALLIANCECONTACT,
                                  addressBookSvc.DeleteEntryMulti,
                                  [[itemID], 'alliancecontact']))
                            else:
                                m += ((mls.UI_CONTACTS_ADDALLIANCECONTACT,
                                  addressBookSvc.AddToPersonalMulti,
                                  [itemID, 'alliancecontact']))
            if ((not (filterFunc and (mls.UI_CMD_VIEWMARKETDETAILS in filterFunc))) and (not ignoreMarketDetails)):
                if session.charid:
                    if (cfg.invtypes.Get(typeID).marketGroupID is not None):
                        m += [(mls.UI_CMD_VIEWMARKETDETAILS,
                          self.ShowMarketDetails,
                          (util.KeyVal(typeID=typeID)))]
                    m += [(mls.UI_CMD_FINDINCONTRACTS,
                      sm.GetService('contracts').FindRelated,
                      (typeID,
                       None,
                       None,
                       None,
                       None,
                       None))]
            return m



    def ParseMenu(self, menuEntries, showInactive, filterFunc = None):
        m = []
        inactive = []
        for menuProps in menuEntries:
            if (menuProps is None):
                m += [None]
                continue
            args = None
            rookieKey = None
            if (len(menuProps) in (2, 3)):
                (label, func, preconditions,) = (menuProps + [[]])[:3]
                if not ((type(func) == tuple) and (func[0] == 'isDynamic')):
                    continue
            elif (len(menuProps) == 4):
                (label, func, args, preconditions,) = menuProps
            else:
                (label, func, args, preconditions, rookieKey,) = menuProps
            if (filterFunc and (label in filterFunc)):
                continue
            inActive = 0
            if rookieKey:
                preconditions = ((sm.StartService('tutorial').GetMenuRookieFilter(rookieKey), False) + preconditions)
            for i in xrange(0, len(preconditions), 2):
                try:
                    ((flag, isTrue, isFalse,), expectedFlag,) = (preconditions[i], preconditions[(i + 1)])
                except:
                    self.LogError('Broken Menu:', label, preconditions)
                    raise 
                if (flag != expectedFlag):
                    if showInactive:
                        if (expectedFlag is True):
                            inactive += [(label, [isFalse, isTrue][(flag == expectedFlag)])]
                        else:
                            inactive += [(label, [isTrue, isFalse][(flag == expectedFlag)])]
                    inActive = 1
                    break

            if inActive:
                continue
            if (args is None):
                m += [(label, func)]
            else:
                m += [(label,
                  func,
                  args)]
                continue

        if inactive:
            inactive = [('Inactive', inactive)]
        return (m + inactive)



    def ChangePartitionLevel(self, level):
        settings.user.ui.Set('partition_box_showall', level)



    def GetPrimedMoons(self, planetID):
        if (eve.session.solarsystemid2 not in self.primedMoons):
            self.PrimeMoons()
        return self.primedMoons[eve.session.solarsystemid2].get(planetID, [])



    def PrimeMoons(self):
        if (eve.session.solarsystemid2 not in self.primedMoons):
            solarsystemitems = sm.RemoteSvc('config').GetMapObjects(eve.session.solarsystemid2, 0, 0, 0, 1, 0)
            moonsByPlanets = {}
            for item in solarsystemitems:
                if (item.groupID != const.groupMoon):
                    continue
                moonsByPlanets.setdefault(item.orbitID, []).append(item)

            self.primedMoons[eve.session.solarsystemid2] = moonsByPlanets



    def GetMoons(self, planetID, moons, *args):
        if len(moons):
            moons = uiutil.SortListOfTuples([ (moon.itemID, moon) for moon in moons ])
            moonmenu = []
            i = 1
            for moon in moons:
                moonmenu.append(((mls.UI_CMD_MOONSUBMENU % {'num': i}), ('isDynamic',
                  self.ExpandMoon,
                  (moon.itemID, moon))))
                i += 1

            return moonmenu
        else:
            return [(mls.UI_CMD_NOMOONS, self.DoNothing)]



    def GetCargoLinkMenu(self, cargoLinkID, *args):
        return sm.StartService('menu').CelestialMenu(cargoLinkID)



    def TransferToCargo(self, itemKey):
        structure = eve.GetInventoryFromId(itemKey[0])
        structure.RemoveChargeToCargo(itemKey)



    def DoNothing(self, *args):
        return 



    def ExpandMoon(self, itemID, moon):
        return sm.StartService('menu').CelestialMenu(itemID, moon)



    def Activate(self, slimItem):
        if (eve.rookieState and (eve.rookieState < 22)):
            return 
        (itemID, groupID, categoryID,) = (slimItem.itemID, slimItem.groupID, slimItem.categoryID)
        if (itemID == eve.session.shipid):
            myship = sm.StartService('godma').GetItem(eve.session.shipid)
            if (myship.groupID == const.groupCapsule):
                bp = sm.StartService('michelle').GetRemotePark()
                if (bp is not None):
                    bp.Stop()
            else:
                self.OpenCargo(itemID, 'My')
            return 
        bp = sm.StartService('michelle').GetBallpark()
        if bp:
            ownBall = bp.GetBall(eve.session.shipid)
            otherBall = bp.GetBall(itemID)
            dist = None
            if (ownBall and otherBall):
                dist = bp.GetSurfaceDist(ownBall.id, otherBall.id)
            if (dist < const.minWarpDistance):
                if ((groupID == const.groupStation) and (dist < const.maxDockingDistance)):
                    self.Dock(itemID)
                elif ((groupID in (const.groupWreck,
                 const.groupCargoContainer,
                 const.groupSecureCargoContainer,
                 const.groupAuditLogSecureContainer,
                 const.groupFreightContainer,
                 const.groupSpawnContainer,
                 const.groupDeadspaceOverseersBelongings)) and (dist < const.maxCargoContainerTransferDistance)):
                    self.OpenCargo(itemID, 'SomeCargo')
                else:
                    self.Approach(itemID, 50)



    def SetDefaultWarpToDist(self, rnge):
        settings.user.ui.Set('defaultWarpToDist', rnge)
        sm.ScatterEvent('OnDistSettingsChange')



    def SetDefaultOrbitDist(self, rnge, *args):
        settings.user.ui.Set('defaultOrbitDist', rnge)
        sm.ScatterEvent('OnDistSettingsChange')



    def SetDefaultKeepAtRangeDist(self, rnge, *args):
        settings.user.ui.Set('defaultKeepAtRangeDist', rnge)
        sm.ScatterEvent('OnDistSettingsChange')



    def ShowDestinyBalls(self, itemID):
        toRemove = None
        scene = sm.GetService('sceneManager').GetRegisteredScene('default')
        for each in scene.children:
            if (each.name == ('miniballs_of_' + str(itemID))):
                toRemove = each
                break

        if toRemove:
            scene.children.remove(toRemove)
            scene = None
            toRemove = None
            return 
        ball = sm.StartService('michelle').GetBallpark().GetBall(itemID)
        t = trinity.TriTransform()
        sphere = blue.os.LoadObject('res:/Model/Global/greenSphere.blue')
        del sphere.children[:]
        ownballs = []
        if (len(ball.miniBalls) > 0):
            for miniball in ball.miniBalls:
                mball = sphere.CopyTo()
                mball.translation.SetXYZ(miniball.x, miniball.y, miniball.z)
                mball.scaling.SetXYZ((miniball.radius * 2), (miniball.radius * 2), (miniball.radius * 2))
                t.children.append(mball)

            t.useCurves = 1
            t.translationCurve = ball
        t.name = ('miniballs_of_' + str(itemID))
        scene.children.append(t)
        scene = None
        t = None
        toRemove = None



    def BallsUp(self, itemID, useDestinyRadius):
        scene = sm.GetService('sceneManager').GetRegisteredScene('default')
        ball = sm.StartService('michelle').GetBallpark().GetBall(itemID)
        if (useDestinyRadius == -1):
            prefix = 'bs'
        elif useDestinyRadius:
            prefix = 'd'
        else:
            prefix = 'm'
        toRemove = None
        for each in scene.children:
            if (each.name == (prefix + str(ball.id))):
                toRemove = each
                break

        if toRemove:
            scene.children.remove(toRemove)
            return 
        if (useDestinyRadius == -1):
            s = trinity.TriTransform()
            b = blue.os.LoadObject('res:/Model/Global/greensphere.blue')
            b.scaling.Scale((ball.model.GetBoundingSphereRadius() * 2.0))
            pos = ball.model.GetBoundingSphereCenter()
            b.translation = trinity.TriVector(pos[0], pos[1], pos[2])
            s.children.append(b)
            s.rotationCurve = ball
        else:
            s = blue.os.LoadObject('res:/model/global/sphere.blue')
            if useDestinyRadius:
                useRadius = ball.radius
            elif hasattr(ball, 'boundingSphereRadius'):
                useRadius = ball.boundingSphereRadius
            else:
                useRadius = ball.radius
            s.scaling.x = useRadius
            s.scaling.y = useRadius
            s.scaling.z = useRadius
            s.scaling.Scale(2.0)
            s.object.areas[0].shader.passes[0].fill = 2
        s.translationCurve = ball
        s.useCurves = 1
        s.name = (prefix + str(ball.id))
        scene.children.append(s)
        scene = None
        s = None
        toRemove = None



    def ShowBallPartition(self, itemID):
        ball = sm.StartService('michelle').GetBallpark().GetBall(itemID)
        ball.showBoxes = 1



    def AnchorObject(self, itemID, anchorFlag):
        dogmaLM = self.godma.GetDogmaLM()
        if dogmaLM:
            typeID = sm.StartService('michelle').GetItem(itemID).typeID
            anchoringDelay = self.godma.GetType(typeID).anchoringDelay
            if anchorFlag:
                eve.Message('AnchoringObject', {'delay': (anchoringDelay / 1000.0)})
                dogmaLM.Activate(itemID, const.effectAnchorDrop)
            else:
                eve.Message('UnanchoringObject', {'delay': (anchoringDelay / 1000.0)})
                dogmaLM.Activate(itemID, const.effectAnchorLift)



    def AnchorStructure(self, itemID, anchorFlag):
        dogmaLM = self.godma.GetDogmaLM()
        if dogmaLM:
            item = sm.StartService('michelle').GetItem(itemID)
            typeID = item.typeID
            if anchorFlag:
                anchoringDelay = self.godma.GetType(typeID).anchoringDelay
                eve.Message('AnchoringObject', {'delay': (anchoringDelay / 1000.0)})
                ball = sm.StartService('michelle').GetBallpark().GetBall(itemID)
                sm.StartService('pwn').Anchor(itemID, (ball.x,
                 ball.y,
                 ball.z))
            else:
                orphaned = self.pwn.StructureIsOrphan(itemID)
                item = sm.StartService('michelle').GetItem(itemID)
                if orphaned:
                    msgName = 'ConfirmOrphanStructureUnanchor'
                elif (item.groupID == const.groupInfrastructureHub):
                    msgName = 'ConfirmInfrastructureHubUnanchor'
                else:
                    msgName = 'ConfirmStructureUnanchor'
                if (eve.Message(msgName, {'item': (TYPEID, item.typeID)}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
                    return 
                unanchoringDelay = self.godma.GetType(typeID).unanchoringDelay
                eve.Message('UnanchoringObject', {'delay': (unanchoringDelay / 1000.0)})
                dogmaLM.Activate(itemID, const.effectAnchorLiftForStructures)



    def ToggleObjectOnline(self, itemID, onlineFlag):
        dogmaLM = self.godma.GetDogmaLM()
        if dogmaLM:
            item = sm.StartService('michelle').GetItem(itemID)
            if onlineFlag:
                if ((item.groupID in (const.groupSovereigntyClaimMarkers)) and (eve.Message('ConfirmSovStructureOnline', {}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES)):
                    return 
                dogmaLM.Activate(itemID, const.effectOnlineForStructures)
            elif (item.groupID == const.groupControlTower):
                msgName = 'ConfirmTowerOffline'
            elif (item.groupID == const.groupSovereigntyClaimMarkers):
                msgName = 'ConfirmSovereigntyClaimMarkerOffline'
            else:
                msgName = 'ConfirmStructureOffline'
            if (eve.Message(msgName, {'item': (TYPEID, item.typeID)}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
                return 
            dogmaLM.Deactivate(itemID, const.effectOnlineForStructures)



    def TransferOwnership(self, itemID):
        members = sm.GetService('alliance').GetMembers()
        twit = sm.GetService('michelle')
        remotePark = twit.GetRemotePark()
        localPark = twit.GetBallpark()
        if (itemID not in localPark.slimItems):
            return 
        oldOwnerID = localPark.slimItems[itemID].ownerID
        owners = []
        for member in members.itervalues():
            if (member.corporationID not in owners):
                owners.append(member.corporationID)

        if len(owners):
            cfg.eveowners.Prime(owners)
        tmplist = []
        for member in members.itervalues():
            if (oldOwnerID != member.corporationID):
                tmplist.append((cfg.eveowners.Get(member.corporationID).ownerName, member.corporationID))

        ret = uix.ListWnd(tmplist, 'generic', mls.UI_CORP_SELECT_CORPORATION, None, 1)
        if ((ret is not None) and len(ret)):
            newOwnerID = ret[1]
            if (remotePark is not None):
                remotePark.ChangeSovStructOwner(itemID, oldOwnerID, newOwnerID)



    def ConfigureObject(self, itemID):
        self.pwn.ConfigureSentryGun(itemID)



    def AskNewContainerPassword(self, id_, desc, which = 1, setnew = '', setold = ''):
        format = [{'type': 'edit',
          'setvalue': (setold or ''),
          'labelwidth': 48,
          'label': mls.UI_GENERIC_OLD,
          'key': 'oldpassword',
          'maxlength': 16,
          'setfocus': 1,
          'passwordChar': '*'},
         {'type': 'edit',
          'setvalue': (setnew or ''),
          'labelwidth': 48,
          'label': mls.UI_GENERIC_NEW,
          'key': 'newpassword',
          'maxlength': 16,
          'passwordChar': '*'},
         {'type': 'edit',
          'setvalue': '',
          'labelwidth': 48,
          'label': mls.UI_GENERIC_CONFIRM,
          'key': 'conpassword',
          'maxlength': 16,
          'passwordChar': '*'}]
        retval = uix.HybridWnd(format, desc, icon=uix.QUESTION, minW=300, minH=75)
        if retval:
            old = (retval['oldpassword'] or None)
            new = (retval['newpassword'] or None)
            con = (retval['conpassword'] or None)
            if ((new is None) or (len(new) < 3)):
                eve.Message('MinThreeLetters')
                return self.AskNewContainerPassword(id_, desc, which, new, old)
            if (new != con):
                eve.Message('NewPasswordMismatch')
                return self.AskNewContainerPassword(id_, desc, which, new, old)
            container = eve.GetInventoryFromId(id_)
            container.SetPassword(which, old, new)



    def LockDownBlueprint(self, invItem):
        dlg = sm.GetService('window').GetWindow('VoteWizardDialog', create=1)
        stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
        blueprints = eve.GetInventory(const.containerGlobal).ListStationBlueprintItems(invItem.locationID, stationID, True)
        description = None
        for blueprint in blueprints:
            if (blueprint.itemID != invItem.itemID):
                continue
            description = ('%s: %s<br>' % (mls.UI_SHARED_LOCATEDAT, cfg.evelocations.Get(stationID).locationName))
            description += ('%s: %s<br>' % (mls.UI_GENERIC_MATERIALEFF, blueprint.materialLevel))
            description += ('%s: %s<br>' % (mls.UI_GENERIC_PRODUCTIVITY, blueprint.productivityLevel))
            break

        dlg.voteType = const.voteItemLockdown
        dlg.voteTitle = (mls.UI_CORP_LOCKDOWNTHE2 % {'item': cfg.invtypes.Get(invItem.typeID).typeName})
        dlg.voteDescription = (description or dlg.voteTitle)
        dlg.voteDays = 1
        dlg.itemID = invItem.itemID
        dlg.typeID = invItem.typeID
        dlg.flagInput = invItem.flagID
        dlg.locationID = stationID
        dlg.GoToStep(len(dlg.steps))
        dlg.ShowModal()



    def UnlockBlueprint(self, invItem):
        voteCases = sm.GetService('corp').GetVoteCasesByCorporation(eve.session.corpid, 2)
        voteCaseIDByItemToUnlockID = {}
        if (voteCases and len(voteCases)):
            for voteCase in voteCases.itervalues():
                if ((voteCase.voteType in [const.voteItemUnlock]) and (voteCase.endDateTime > (blue.os.GetTime() - DAY))):
                    options = sm.GetService('corp').GetVoteCaseOptions(voteCase.voteCaseID, voteCase.corporationID)
                    if len(options):
                        for option in options.itervalues():
                            if option.parameter:
                                voteCaseIDByItemToUnlockID[option.parameter] = voteCase.voteCaseID


        if voteCaseIDByItemToUnlockID.has_key(invItem.itemID):
            raise UserError('CustomInfo', {'info': mls.UI_CORP_UNLOCK_VOTE_ALREADY_EXISTS})
        sanctionedActionsInEffect = sm.GetService('corp').GetSanctionedActionsByCorporation(eve.session.corpid, 1).itervalues()
        sanctionedActionsByLockedItemID = util.IndexRowset(sanctionedActionsInEffect.header, [], 'parameter')
        if (sanctionedActionsInEffect and len(sanctionedActionsInEffect)):
            for sanctionedActionInEffect in sanctionedActionsInEffect:
                if ((sanctionedActionInEffect.voteType in [const.voteItemLockdown]) and (sanctionedActionInEffect.parameter and sanctionedActionInEffect.inEffect)):
                    sanctionedActionsByLockedItemID[sanctionedActionInEffect.parameter] = sanctionedActionInEffect.line

        if not sanctionedActionsByLockedItemID.has_key(invItem.itemID):
            raise UserError('CustomInfo', {'info': mls.UI_CORP_CANNOT_UNLOCK_NO_LOCKDOWN_SANCTIONEDACTION})
        dlg = sm.GetService('window').GetWindow('VoteWizardDialog', create=1)
        stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
        blueprints = eve.GetInventory(const.containerGlobal).ListStationBlueprintItems(invItem.locationID, stationID, True)
        description = None
        for blueprint in blueprints:
            if (blueprint.itemID != invItem.itemID):
                continue
            description = ('%s: %s<br>' % (mls.UI_SHARED_LOCATEDAT, cfg.evelocations.Get(stationID).locationName))
            description += ('%s: %s<br>' % (mls.UI_GENERIC_MATERIALEFF, blueprint.materialLevel))
            description += ('%s: %s<br>' % (mls.UI_GENERIC_PRODUCTIVITY, blueprint.productivityLevel))
            break

        dlg.voteType = const.voteItemUnlock
        dlg.voteTitle = (mls.UI_CORP_UNLOCKTHE2 % {'item': cfg.invtypes.Get(invItem.typeID).typeName})
        dlg.voteDescription = (description or dlg.voteTitle)
        dlg.voteDays = 1
        dlg.itemID = invItem.itemID
        dlg.typeID = invItem.typeID
        dlg.flagInput = invItem.flagID
        dlg.locationID = stationID
        dlg.GoToStep(len(dlg.steps))
        dlg.ShowModal()



    def ALSCLock(self, invItems):
        for item in invItems:
            container = eve.GetInventoryFromId(item.locationID)
            container.LockItem(item.itemID)




    def ALSCUnlock(self, invItems):
        for item in invItems:
            container = eve.GetInventoryFromId(item.locationID)
            container.UnlockItem(item.itemID)




    def ViewAuditLogForALSC(self, itemID):
        sm.GetService('window').GetWindow('alsclogviewer', create=1, decoClass=form.AuditLogSecureContainerLogViewer, itemID=itemID)



    def ConfigureALSC(self, itemID):
        container = eve.GetInventoryFromId(itemID)
        config = None
        if (((charsession.corprole & const.corpRoleEquipmentConfig) > 0) or 1):
            try:
                config = container.ALSCConfigGet()
            except UserError, e:
                pass
        defaultLock = settings.user.ui.Get(('defaultContainerLock_%s' % itemID), None)
        if (defaultLock is None):
            defaultLock = const.flagLocked
        format = []
        format.append({'type': 'header',
         'text': mls.UI_INFLIGHT_DEFAULTLOCKED,
         'frame': 1})
        m = [(const.flagLocked, mls.UI_GENERIC_LOCKED), (const.flagUnlocked, mls.UI_GENERIC_UNLOCKED)]
        for (value, settingName,) in m:
            format.append({'type': 'checkbox',
             'setvalue': (defaultLock == value),
             'key': value,
             'label': '',
             'text': settingName,
             'frame': 1,
             'group': 'defaultContainerLock'})

        format.append({'type': 'btline'})
        format.append({'type': 'push'})
        if (config is not None):
            format.append({'type': 'header',
             'text': mls.UI_INFLIGHT_REQUIREPASSWORDFOR,
             'frame': 1})
            configSettings = [[const.ALSCPasswordNeededToOpen, mls.UI_INFLIGHT_CONTAINERPASSWORDFOROPENING],
             [const.ALSCPasswordNeededToLock, mls.UI_INFLIGHT_CONTAINERPASSWORDFORLOCKING],
             [const.ALSCPasswordNeededToUnlock, mls.UI_INFLIGHT_CONTAINERPASSWORDFORUNLOCKING],
             [const.ALSCPasswordNeededToViewAuditLog, mls.UI_INFLIGHT_CONTAINERPASSWORDFORVIEWINGLOG]]
            for (value, settingName,) in configSettings:
                format.append({'type': 'checkbox',
                 'setvalue': ((value & config) == value),
                 'key': value,
                 'label': '',
                 'text': settingName,
                 'frame': 1})

            format.append({'type': 'btline'})
            format.append({'type': 'push'})
        retval = uix.HybridWnd(format, mls.UI_INFLIGHT_CONTAINERCONFIGURATION, 1, None, uix.OKCANCEL, unresizeAble=1, minW=300)
        if (retval is None):
            return 
        newconfig = 0
        for (k, v,) in retval.iteritems():
            if (k in (const.flagLocked, const.flagUnlocked)):
                pass
            else:
                continue
                if (k == 'defaultContainerLock'):
                    settings.user.ui.Set(('defaultContainerLock_%s' % itemID), v)
                else:
                    newconfig += (k * v)

        if (config is not None):
            container.ALSCConfigSet(newconfig)



    def RetrievePasswordALSC(self, itemID):
        container = eve.GetInventoryFromId(itemID)
        format = []
        format.append({'type': 'header',
         'text': mls.UI_INFLIGHT_WHICHPASSWORD,
         'frame': 1})
        format.append({'type': 'push'})
        format.append({'type': 'btline'})
        configSettings = [[const.SCCPasswordTypeGeneral, mls.UI_GENERIC_GENERAL], [const.SCCPasswordTypeConfig, mls.UI_GENERIC_CONFIGURATION]]
        for (value, settingName,) in configSettings:
            format.append({'type': 'checkbox',
             'setvalue': ((value & const.SCCPasswordTypeGeneral) == value),
             'key': value,
             'label': '',
             'text': settingName,
             'frame': 1,
             'group': 'which_password'})

        format.append({'type': 'btline'})
        retval = uix.HybridWnd(format, mls.UI_CMD_RETRIEVEPASSWORD, 1, None, uix.OKCANCEL)
        if (retval is None):
            return 
        container.RetrievePassword(retval['which_password'])



    def GetFleetMemberMenu(self, func, args):
        menuSize = 20
        m = []
        fleet = []
        for member in sm.GetService('fleet').GetMembers().itervalues():
            if (member.charID == session.charid):
                continue
            data = cfg.eveowners.Get(member.charID)
            fleet.append((uiutil.UpperCase(data.name), (member.charID, data.name)))

        fleet = uiutil.SortListOfTuples(fleet)
        all = []
        while (len(fleet) > menuSize):
            all.append(fleet[:menuSize])
            fleet = fleet[menuSize:]

        if fleet:
            all.append(fleet)
        if not all:
            return []
        else:
            if (len(all) == 1):
                return self.GetSubFleetMemberMenu(all[0], func, args)
            return [ (('%c ... %c' % (sub[0][1][0], sub[-1][1][0])), ('isDynamic',
              self.GetSubFleetMemberMenu,
              (sub,
               func,
               args))) for sub in all ]



    def GetSubFleetMemberMenu(self, memberIDs, func, args):
        return [ [name,
         func,
         (charID, args)] for (charID, name,) in memberIDs ]



    def BridgeToMember(self, charID):
        beaconStuff = sm.GetService('fleet').GetActiveBeaconForChar(charID)
        if (beaconStuff is None):
            return 
        self.BridgeToBeacon(charID, beaconStuff)



    def BridgeToBeaconAlliance(self, solarSystemID, beaconID):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        bp.BridgeToStructure(beaconID, solarSystemID)



    def BridgeToBeacon(self, charID, beacon):
        (solarsystemID, beaconID,) = beacon
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        bp.BridgeToMember(charID, beaconID, solarsystemID)



    def JumpThroughFleet(self, otherCharID, otherShipID):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        bridge = sm.GetService('fleet').GetActiveBridgeForShip(otherShipID)
        if (bridge is None):
            return 
        (solarsystemID, beaconID,) = bridge
        self.LogNotice('Jump Through Fleet', otherCharID, otherShipID, beaconID, solarsystemID)
        sm.StartService('sessionMgr').PerformSessionChange('jump', bp.JumpThroughFleet, otherCharID, otherShipID, beaconID, solarsystemID)



    def JumpThroughAlliance(self, otherShipID):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        bridge = sm.StartService('pwn').GetActiveBridgeForShip(otherShipID)
        if (bridge is None):
            return 
        (solarsystemID, beaconID,) = bridge
        self.LogNotice('Jump Through Alliance', otherShipID, beaconID, solarsystemID)
        sm.StartService('sessionMgr').PerformSessionChange('jump', bp.JumpThroughAlliance, otherShipID, beaconID, solarsystemID)



    def JumpToMember(self, charid):
        beaconStuff = sm.GetService('fleet').GetActiveBeaconForChar(charid)
        if (beaconStuff is None):
            return 
        self.JumpToBeaconFleet(charid, beaconStuff)



    def JumpToBeaconFleet(self, charid, beacon):
        (solarsystemID, beaconID,) = beacon
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        self.LogNotice('Jump To Beacon Fleet', charid, beaconID, solarsystemID)
        for wnd in sm.GetService('window').GetWindows()[:]:
            if (getattr(wnd, '__guid__', None) == 'form.CorpHangarArray'):
                wnd.CloseX()

        sm.StartService('sessionMgr').PerformSessionChange('jump', bp.BeaconJumpFleet, charid, beaconID, solarsystemID)



    def JumpToBeaconAlliance(self, solarSystemID, beaconID):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        self.LogNotice('Jump To Beacon Alliance', beaconID, solarSystemID)
        sm.StartService('sessionMgr').PerformSessionChange('jump', bp.BeaconJumpAlliance, beaconID, solarSystemID)



    def ActivateGridSmartBomb(self, charid, effect):
        beaconStuff = sm.GetService('fleet').GetActiveBeaconForChar(charid)
        if (beaconStuff is None):
            return 
        (solarsystemID, beaconID,) = beaconStuff
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is None):
            return 
        effect.Activate(beaconID, False)



    def LeaveFleet(self):
        sm.GetService('fleet').LeaveFleet()



    def MakeLeader(self, charid):
        sm.GetService('fleet').MakeLeader(charid)



    def KickMember(self, charid):
        sm.GetService('fleet').KickMember(charid)



    def DisbandFleet(self):
        sm.GetService('fleet').DisbandFleet()



    def InviteToFleet(self, charIDs, ignoreWars = 0):
        if (type(charIDs) != list):
            charIDs = [charIDs]
        charErrors = {}
        for charID in charIDs:
            try:
                sm.GetService('fleet').Invite(charID, None, None, None)
            except UserError, ue:
                charErrors[charID] = ue
                sys.exc_clear()

        if (len(charErrors) == 1):
            raise charErrors.values()[0]
        elif (len(charErrors) > 1):
            charNames = None
            for charID in charErrors.iterkeys():
                if (charNames is not None):
                    charNames += (', %s' % cfg.eveowners.Get(charID).name)
                else:
                    charNames = cfg.eveowners.Get(charID).name

            raise UserError('FleetInviteMultipleErrors', {'namelist': charNames})



    def Regroup(self, *args):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            bp.FleetRegroup()



    def WarpFleet(self, id, warpRange = None):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            bp.WarpToStuff('item', id, minRange=warpRange, fleet=True)
            sm.StartService('space').WarpDestination(id, None, None)



    def WarpToMember(self, charID, warpRange = None):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            bp.WarpToStuff('char', charID, minRange=warpRange)
            sm.StartService('space').WarpDestination(None, None, charID)



    def WarpFleetToMember(self, charID, warpRange = None):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            bp.WarpToStuff('char', charID, minRange=warpRange, fleet=True)
            sm.StartService('space').WarpDestination(None, None, charID)



    def TacticalItemClicked(self, itemID):
        isTargeted = sm.GetService('target').IsTarget(itemID)
        if isTargeted:
            sm.GetService('state').SetState(itemID, state.activeTarget, 1)
        uicore.cmd.ExecuteCombatCommand(itemID, uiconst.UI_CLICK)



    def KeepAtRange(self, id, range = None):
        if (id == session.shipid):
            return 
        if (range is None):
            range = self.GetDefaultDist('KeepAtRange', id, minDist=50)
        bp = sm.StartService('michelle').GetRemotePark()
        if ((bp is not None) and (range is not None)):
            name = sm.GetService('space').GetWarpDestinationName(id)
            eve.Message('Command', {'command': (mls.UI_INFLIGHT_KEEPINGATRANGE % {'name': name,
                         'range': range})})
            bp.FollowBall(id, range)



    def Approach(self, id, range = None):
        if (id == session.shipid):
            return 
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            name = sm.GetService('space').GetWarpDestinationName(id)
            eve.Message('Command', {'command': (mls.UI_INFLIGHT_APPROACHINGITEM % {'name': name})})
            bp.FollowBall(id, (range or 50))



    def AlignTo(self, id):
        if (id == session.shipid):
            return 
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            name = sm.GetService('space').GetWarpDestinationName(id)
            eve.Message('Command', {'command': (mls.UI_INFLIGHT_ALIGNINGTO % {'name': name})})
            bp.AlignTo(id)



    def AlignToBookmark(self, id):
        bp = sm.StartService('michelle').GetRemotePark()
        if (bp is not None):
            bp.AlignTo(bookmarkID=id)



    def Orbit(self, id, range = None):
        if (id == session.shipid):
            return 
        if (range is None):
            range = self.GetDefaultDist('Orbit')
        bp = sm.StartService('michelle').GetRemotePark()
        if ((bp is not None) and (range is not None)):
            name = sm.GetService('space').GetWarpDestinationName(id)
            range = (float(range) if (range < 10.0) else int(range))
            eve.Message('Command', {'command': (mls.UI_INFLIGHT_ORBITING % {'name': name,
                         'range': range})})
            bp.Orbit(id, range)



    def TagItem(self, itemID, tag):
        bp = sm.StartService('michelle').GetRemotePark()
        if bp:
            bp.FleetTagTarget(itemID, tag)



    def LockTarget(self, id):
        sm.StartService('target').LockTarget(id)



    def UnlockTarget(self, id):
        sm.StartService('target').UnlockTarget(id)



    def ShowInfo(self, typeID, itemID = None, new = 0, rec = None, parentID = None, *args):
        sm.StartService('info').ShowInfo(typeID, itemID, new, rec, parentID)



    def ShowInfoForItem(self, itemID):
        bp = sm.StartService('michelle').GetBallpark()
        if bp:
            itemTypeID = bp.GetInvItem(itemID).typeID
            sm.GetService('info').ShowInfo(itemTypeID, itemID)



    def DockOrJumpOrActivateGate(self, itemID):
        bp = sm.StartService('michelle').GetBallpark()
        menuSvc = sm.GetService('menu')
        if bp:
            groupID = bp.GetInvItem(itemID).groupID
            if (groupID == const.groupStation):
                menuSvc.Dock(itemID)
            if (groupID == const.groupStargate):
                bp = sm.StartService('michelle').GetBallpark()
                slimItem = bp.slimItems.get(itemID)
                if slimItem:
                    jump = slimItem.jumps[0]
                    if not jump:
                        return 
                    menuSvc.StargateJump(itemID, jump.toCelestialID, jump.locationID)
            else:
                if (groupID == const.groupWarpGate):
                    menuSvc.ActivateAccelerationGate(itemID)



    def PreviewType(self, typeID):
        sm.GetService('preview').PreviewType(typeID)



    def GetDefaultDist(self, forWhat, itemID = None, minDist = 500, maxDist = 1000000):
        drange = sm.GetService('menu').GetDefaultActionDistance(forWhat)
        if (drange is None):
            dist = ''
            if itemID:
                bp = sm.StartService('michelle').GetBallpark()
                if not bp:
                    return 
                ball = bp.GetBall(itemID)
                if not ball:
                    return 
                dist = long(max(minDist, min(maxDist, ball.surfaceDist)))
            hint = (mls.UI_INFLIGHT_SETDEFAULTDISTHINT % {'typeName': getattr(mls, ('UI_CMD_' + forWhat.upper()), forWhat),
             'fromDist': util.FmtAmt(minDist),
             'toDist': util.FmtAmt(maxDist)})
            r = uix.QtyPopup(maxvalue=maxDist, minvalue=minDist, setvalue=dist, hint=hint, caption=(mls.UI_INFLIGHT_SETDEFAULTDIST % {'typeName': getattr(mls, ('UI_CMD_' + forWhat.upper()), forWhat)}), label=None, digits=0)
            if r:
                drange = max(minDist, min(maxDist, r['qty']))
                settings.user.ui.Set(('default%sDist' % forWhat), drange)
                sm.ScatterEvent('OnDistSettingsChange')
            else:
                return 
        return drange



    def ApproachLocation(self, bookmark):
        bp = sm.StartService('michelle').GetRemotePark()
        if bp:
            if (getattr(bookmark, 'agentID', 0) and hasattr(bookmark, 'locationNumber')):
                referringAgentID = getattr(bookmark, 'referringAgentID', None)
                sm.StartService('agents').GetAgentMoniker(bookmark.agentID).GotoLocation(bookmark.locationType, bookmark.locationNumber, referringAgentID)
            else:
                bp.GotoBookmark(bookmark.bookmarkID)



    def WarpToBookmark(self, bookmark, warpRange = 20000.0, fleet = False):
        bp = sm.StartService('michelle').GetRemotePark()
        if bp:
            if (getattr(bookmark, 'agentID', 0) and hasattr(bookmark, 'locationNumber')):
                referringAgentID = getattr(bookmark, 'referringAgentID', None)
                sm.StartService('agents').GetAgentMoniker(bookmark.agentID).WarpToLocation(bookmark.locationType, bookmark.locationNumber, warpRange, fleet, referringAgentID)
            else:
                bp.WarpToStuff('bookmark', bookmark.bookmarkID, minRange=warpRange, fleet=fleet)
                sm.StartService('space').WarpDestination(None, bookmark.bookmarkID, None)



    def WarpToItem(self, id, warpRange = None):
        if (id == session.shipid):
            return 
        if (warpRange is None):
            warprange = sm.GetService('menu').GetDefaultActionDistance('WarpTo')
        else:
            warprange = warpRange
        bp = sm.StartService('michelle').GetRemotePark()
        if ((bp is not None) and sm.StartService('space').CanWarp(id)):
            bp.WarpToStuff('item', id, minRange=warprange)
            sm.StartService('space').WarpDestination(id, None, None)



    def StoreVessel(self, destID, shipID):
        if (shipID != session.shipid):
            return 
        shipItem = self.godma.GetStateManager().GetItem(shipID)
        if (shipItem.groupID == const.groupCapsule):
            return 
        destItem = uix.GetBallparkRecord(destID)
        if (destItem.categoryID == const.categoryShip):
            msgName = 'ConfirmStoreVesselInShip'
        else:
            msgName = 'ConfirmStoreVesselInStructure'
        if (eve.Message(msgName, {'dest': (TYPEID, destItem.typeID)}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
            return 
        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            sm.StartService('sessionMgr').PerformSessionChange('storeVessel', ship.StoreVessel, destID)



    def OpenCorpHangarArray(self, id, name):
        if getattr(self, '_openingCorpHangarArray', 0):
            return 
        self._openingCorpHangarArray = 1
        uthread.new(self._OpenCorpHangarArray, id, name)



    def _OpenCorpHangarArray(self, id, name):
        try:
            sm.StartService('window').OpenCorpHangarArray(id, name, locationFlag=const.flagNone, hasCapacity=1, nameLabel='corpHangar')

        finally:
            self._openingCorpHangarArray = 0




    def OpenShipCorpHangars(self, id, name):
        if getattr(self, '_openingCorpHangarArray', 0):
            return 
        self._openingShipCorpHangars = 1
        uthread.new(self._OpenShipCorpHangars, id, name)



    def _OpenShipCorpHangars(self, id, name):
        try:
            sm.StartService('window').OpenShipCorpHangars(id, name, locationFlag=const.flagNone, hasCapacity=1, nameLabel='corpHangar')

        finally:
            self._openingShipCorpHangars = 0




    def OpenStructure(self, id, name):
        if getattr(self, '_openingStructure', 0):
            return 
        self._openingStructure = 1
        uthread.new(self._OpenStructure, id, name)



    def _OpenStructure(self, id, name):
        try:
            sm.StartService('window').OpenContainer(id, name, locationFlag=const.flagNone, hasCapacity=1, nameLabel='structure')

        finally:
            self._openingStructure = 0




    def OpenStructureCargo(self, id, name):
        if getattr(self, '_openingStructureCargo', 0):
            return 
        self._openingStructureCargo = 1
        uthread.new(self._OpenStructureCargo, id, name)



    def _OpenStructureCargo(self, id, name):
        try:
            sm.StartService('window').OpenContainer(id, name, locationFlag=const.flagCargo, hasCapacity=1, nameLabel='cargo')

        finally:
            self._openingStructureCargo = 0




    def OpenStructureCharges(self, id, name, showCapacity = 0):
        if getattr(self, '_openingStructureCharges', 0):
            return 
        self._openingStructureCharges = 1
        uthread.new(self._OpenStructureCharges, id, name, showCapacity)



    def _OpenStructureCharges(self, id, name, showCapacity):
        try:
            sm.StartService('window').OpenContainer(id, name, locationFlag=const.flagHiSlot0, hasCapacity=showCapacity, nameLabel=name)

        finally:
            self._openingStructureCharges = 0




    def OpenStrontiumBay(self, id, name):
        if getattr(self, '_openingStrontiumBay', 0):
            return 
        self._openingStrontiumBay = 1
        uthread.new(self._OpenStrontiumBay, id, name)



    def _OpenStrontiumBay(self, id, name):
        try:
            sm.StartService('window').OpenContainer(id, name, locationFlag=const.flagSecondaryStorage, hasCapacity=1, nameLabel=name)

        finally:
            self._openingStrontiumBay = 0




    def ManageControlTower(self, id):
        uthread.new(self._ManageControlTower, id)



    def _ManageControlTower(self, id):
        uicore.cmd.OpenMoonMining(id)



    def OpenConstructionPlatform(self, id, name):
        if getattr(self, '_openingPlatform', 0):
            return 
        self._openingPlatform = 1
        uthread.new(self._OpenConstructionPlatform, id, name)



    def _OpenConstructionPlatform(self, id, name):
        try:
            sm.StartService('window').OpenContainer(id, name)

        finally:
            self._openingPlatform = 0




    def BuildConstructionPlatform(self, id):
        if getattr(self, '_buildingPlatform', 0):
            return 
        self._buildingPlatform = 1
        uthread.new(self._BuildConstructionPlatform, id)



    def _BuildConstructionPlatform(self, id):
        try:
            securityCode = None
            shell = eve.GetInventoryFromId(id)
            while 1:
                try:
                    if (securityCode is None):
                        shell.Build()
                    else:
                        shell.Build(securityCode=securityCode)
                    break
                except UserError, what:
                    if (what.args[0] == 'PermissionDenied'):
                        if securityCode:
                            caption = mls.UI_GENERIC_INCORRECTPASSWORD
                            label = mls.UI_GENERIC_PLEASETRYAGAIN
                        else:
                            caption = mls.UI_GENERIC_PASSWORDREQUIRED
                            label = mls.UI_GENERIC_PLEASEENTERPASSWORD
                        passw = uix.NamePopup(caption=caption, label=label, setvalue='', icon=-1, modal=1, btns=None, maxLength=50, passwordChar='*')
                        if (passw is None):
                            raise UserError('IgnoreToTop')
                        else:
                            securityCode = passw['name']
                    else:
                        raise 
                    sys.exc_clear()


        finally:
            self._buildingPlatform = 0




    def Bookmark(self, itemID, typeID, parentID, note = None):
        sm.StartService('addressbook').BookmarkLocationPopup(itemID, typeID, parentID, note)



    def ShowInMapBrowser(self, itemID, *args):
        uicore.cmd.OpenMapBrowser(itemID)



    def ShowInMap(self, itemID, *args):
        if eve.session.stationid:
            sm.GetService('station').CleanUp()
        sm.GetService('map').OpenStarMap()
        sm.GetService('starmap').SetInterest(itemID, forceframe=1)



    def Dock(self, id):
        bp = sm.StartService('michelle').GetBallpark()
        if not bp:
            return 
        station = bp.GetBall(id)
        if not station:
            return 
        station.GetVectorAt(blue.os.GetTime())
        if (station.surfaceDist >= const.minWarpDistance):
            self.WarpDock(id)
        else:
            eve.Message('OnDockingRequest')
            eve.Message('Command', {'command': (mls.UI_INFLIGHT_REQUESTTODOCKAT % {'station': cfg.evelocations.Get(id).name})})
            paymentRequired = 0
            try:
                bp = sm.GetService('michelle').GetRemotePark()
                if (bp is not None):
                    self.LogNotice('Docking', id)
                    if (eve.triapp.uilib.Key(uix.VK_CONTROL) and (eve.triapp.uilib.Key(uix.VK_SHIFT) and (eve.triapp.uilib.Key(uix.VK_MENU) and (eve.session.role & service.ROLE_GML)))):
                        success = sm.GetService('sessionMgr').PerformSessionChange('dock', bp.TurboDock, id)
                    else:
                        success = sm.GetService('sessionMgr').PerformSessionChange('dock', bp.Dock, id, session.shipid)
            except UserError, e:
                if (e.msg == 'DockingRequestDeniedPaymentRequired'):
                    sys.exc_clear()
                    paymentRequired = e.args[1]['amount']
                else:
                    raise 
            except Exception, e:
                raise 
            if paymentRequired:
                try:
                    if (eve.Message('AskPayDockingFee', {'cost': util.FmtAmt(paymentRequired)}, uix.YESNO) == uix.ID_YES):
                        bp = sm.GetService('michelle').GetRemotePark()
                        if (bp is not None):
                            eve.session.ResetSessionChangeTimer('Retrying with docking payment')
                            if (eve.triapp.uilib.Key(uix.VK_CONTROL) and (eve.session.role & service.ROLE_GML)):
                                success = sm.GetService('sessionMgr').PerformSessionChange('dock', bp.TurboDock, id, paymentRequired)
                            else:
                                success = sm.GetService('sessionMgr').PerformSessionChange('dock', bp.Dock, id, session.shipid, paymentRequired)
                except Exception, e:
                    raise 



    def CancelWarpDock(self):
        self.warpDocking = False



    def DefaultWarpToLabel(self):
        defaultWarpDist = sm.GetService('menu').GetDefaultActionDistance('WarpTo')
        return ((mls.UI_CMD_WARPTOWITHIN % {'dist': util.FmtDist(float(defaultWarpDist))}), menu.ACTIONSGROUP)



    def WarpDock(self, id):
        bp = sm.StartService('michelle').GetRemotePark()
        if ((bp is not None) and sm.StartService('space').CanWarp()):
            eve.Message('Command', {'command': (mls.UI_INFLIGHT_WARPTOPRIORLOCATION % {'location': cfg.evelocations.Get(id).name})})
            self.warpDocking = True
            try:
                bp.WarpToStuff('item', id)
                sm.StartService('space').WarpDestination(id, None, None)
                michelle = sm.StartService('michelle')
                ball = michelle.GetBall(eve.session.shipid)
                while (self.warpDocking and (ball.mode != destiny.DSTBALL_WARP)):
                    blue.pyos.synchro.Sleep(500)

                while (self.warpDocking and (ball.mode == destiny.DSTBALL_WARP)):
                    blue.pyos.synchro.Sleep(500)

                if self.warpDocking:
                    self.Dock(id)

            finally:
                self.warpDocking = False




    def GetIllegality(self, itemID, typeID = None, solarSystemID = None):
        if (solarSystemID is None):
            solarSystemID = eve.session.solarsystemid
        toFactionID = sm.StartService('faction').GetFactionOfSolarSystem(solarSystemID)
        if ((typeID is not None) and (cfg.invtypes.Get(typeID).groupID not in (const.groupCargoContainer,
         const.groupSecureCargoContainer,
         const.groupAuditLogSecureContainer,
         const.groupFreightContainer))):
            if cfg.invtypes.Get(typeID).Illegality(toFactionID):
                return cfg.invtypes.Get(typeID).name
            else:
                return ''
            stuff = ''
            invItem = sm.GetService('invCache').GetInventoryFromId(itemID)
            for item in invItem.List():
                try:
                    illegality = cfg.invtypes.Get(item.typeID).Illegality(toFactionID)
                    if illegality:
                        stuff += (cfg.invtypes.Get(item.typeID).name + ', ')
                    if (cfg.invtypes.Get(item.typeID).groupID in (const.groupCargoContainer,
                     const.groupSecureCargoContainer,
                     const.groupAuditLogSecureContainer,
                     const.groupFreightContainer)):
                        sublegality = self.GetIllegality(item.itemID, solarSystemID=solarSystemID)
                        if sublegality:
                            stuff += (sublegality + ', ')
                except:
                    log.LogTraceback('bork in illegality check 2')
                    sys.exc_clear()

            return stuff[:-2]



    def StargateJump(self, id, beaconID = None, solarSystemID = None):
        if beaconID:
            bp = sm.StartService('michelle').GetRemotePark()
            if (bp is not None):
                if (solarSystemID is not None):
                    fromFactionID = sm.StartService('faction').GetFactionOfSolarSystem(eve.session.solarsystemid)
                    toFactionID = sm.StartService('faction').GetFactionOfSolarSystem(solarSystemID)
                    if (toFactionID and (fromFactionID != toFactionID)):
                        stuff = self.GetIllegality(eve.session.shipid, solarSystemID=solarSystemID)
                        if (stuff and (eve.Message('ConfirmJumpWithIllicitGoods', {'faction': cfg.eveowners.Get(toFactionID).name,
                         'stuff': stuff}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES)):
                            return 
                    sec = sm.StartService('map').GetSecurityStatus(solarSystemID)
                    toSecClass = sm.StartService('map').GetSecurityClass(solarSystemID)
                    fromSecClass = sm.StartService('map').GetSecurityClass(eve.session.solarsystemid)
                    if (toSecClass <= const.securityClassLowSec):
                        if ((fromSecClass >= const.securityClassHighSec) and (eve.Message('ConfirmJumpToUnsafeSS', {'ss': sec}, uix.OKCANCEL) != uix.ID_OK)):
                            return 
                    else:
                        if (fromSecClass <= const.securityClassLowSec):
                            (charcrimes, corpcrimes,) = sm.GetService('michelle').GetCriminalFlagCountDown()
                            if (charcrimes.has_key(None) and (eve.Message('JumpCriminalConfirm', {}, uix.YESNO) != uix.ID_YES)):
                                return 
                self.LogNotice('Stargate Jump from', session.solarsystemid2, 'to', id)
                sm.StartService('sessionMgr').PerformSessionChange(mls.UI_CMD_JUMP, bp.StargateJump, id, beaconID, session.shipid)



    def ActivateAccelerationGate(self, id):
        if (eve.rookieState and (not sm.StartService('tutorial').CheckAccelerationGateActivation())):
            return 
        sm.StartService('sessionMgr').PerformSessionChange(mls.UI_CMD_ACTIVATEGATE, sm.RemoteSvc('keeper').ActivateAccelerationGate, id, violateSafetyTimer=1)
        self.LogNotice('Acceleration Gate activated to ', id)



    def EnterWormhole(self, itemID):
        fromSecClass = sm.StartService('map').GetSecurityClass(eve.session.solarsystemid)
        if ((fromSecClass == const.securityClassHighSec) and (eve.Message('WormholeJumpingFromHiSec', {}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES)):
            return 
        probes = sm.StartService('scanSvc').GetProbeData()
        if (((probes is not None) and (len(probes) > 0)) and (eve.Message('WormholeLeaveProbesConfirm', {'probes': len(probes)}, uix.YESNO) != uix.ID_YES)):
            return 
        self.LogNotice('Wormhole Jump from', session.solarsystemid2, 'to', itemID)
        sm.StartService('sessionMgr').PerformSessionChange(mls.UI_CMD_ENTERWORMHOLE, sm.RemoteSvc('wormholeMgr').WormholeJump, itemID)



    def CopyItemIDToClipboard(self, itemID):
        blue.pyos.SetClipboardData(str(itemID))



    def StopMyShip(self):
        uicore.cmd.CmdStopShip()



    def AbortWarpDock(self):
        self.warpDocking = False



    def OpenCargo(self, id, *args):
        if getattr(self, '_openingCargo', 0):
            return 
        self._openingCargo = 1
        uthread.new(self._OpenCargo, id)



    def _OpenCargo(self, _id):
        if (type(_id) != types.ListType):
            _id = [_id]
        for id in _id:
            try:
                if (id == eve.session.shipid):
                    uicore.cmd.OpenCargoHoldOfActiveShip()
                else:
                    slim = sm.GetService('michelle').GetItem(id)
                    if (slim and (slim.groupID == const.groupWreck)):
                        sm.StartService('window').OpenContainer(id, mls.UI_INFLIGHT_WRECK, hasCapacity=0, isWreck=True, windowPrefsID='lootCargoContainer')
                    else:
                        sm.StartService('window').OpenContainer(id, mls.UI_INFLIGHT_FLOATINGCARGO, hasCapacity=1, windowPrefsID='lootCargoContainer')

            finally:
                self._openingCargo = 0





    def OpenPlanetCargoLinkInventory(self, invItems):
        for invItemID in invItems:
            sm.StartService('window').OpenPlanetCargoLink(invItemID, mls.UI_PI_GENERIC_SPACEPORT)




    def OpenPlanetCargoLinkImportWindow(self, cargoLinkID):
        sm.GetService('planetUI').OpenPlanetCargoLinkImportWindow(cargoLinkID)



    def AbandonLoot(self, wreckID, *args):
        twit = sm.GetService('michelle')
        localPark = twit.GetBallpark()
        allowedGroup = None
        if (wreckID in localPark.slimItems):
            allowedGroup = localPark.slimItems[wreckID].groupID
        if (eve.Message('ConfirmAbandonLoot', {'type': (GROUPID, allowedGroup)}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
            return 
        remotePark = sm.GetService('michelle').GetRemotePark()
        if (remotePark is not None):
            remotePark.AbandonLoot([wreckID])



    def AbandonAllLoot(self, wreckID, *args):
        twit = sm.GetService('michelle')
        localPark = twit.GetBallpark()
        remotePark = twit.GetRemotePark()
        if (remotePark is None):
            return 
        wrecks = []
        allowedGroup = None
        if (wreckID in localPark.slimItems):
            allowedGroup = localPark.slimItems[wreckID].groupID
        if (eve.Message('ConfirmAbandonLootAll', {'type': (GROUPID, allowedGroup)}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
            return 
        bp = sm.GetService('michelle').GetBallpark()
        fleetSvc = sm.GetService('fleet')
        for (itemID, slimItem,) in localPark.slimItems.iteritems():
            if (slimItem.groupID == allowedGroup):
                lootRights = getattr(slimItem, 'lootRights', [])
                if ((lootRights is not None) and (None in lootRights)):
                    continue
                canLoot = (session.charid == slimItem.ownerID)
                if not canLoot:
                    if (lootRights is not None):
                        canLoot = ((session.charid in lootRights) or (session.corpid in lootRights))
                if not canLoot:
                    if (fleetSvc.IsMember(slimItem.ownerID) or bp.HaveLootRight(slimItem.itemID)):
                        canLoot = True
                if not canLoot:
                    pass
            wrecks.append(itemID)
            continue

        if (remotePark is not None):
            remotePark.AbandonLoot(wrecks)



    def OpenShipMaintenanceBayShip(self, id, name):
        if getattr(self, '_openingSMA', 0):
            return 
        self._openingSMA = 1
        uthread.new(self._OpenShipMaintenanceBayShip, id, name)



    def _OpenShipMaintenanceBayShip(self, id, name):
        try:
            sm.StartService('window').OpenContainer(id, name, locationFlag=const.flagShipHangar, hasCapacity=1, nameLabel='sma')

        finally:
            self._openingSMA = 0




    def ShipConfig(self, id = None):
        if (id == eve.session.shipid):
            uthread.new(self._ShipConfig)



    def _ShipConfig(self):
        uicore.cmd.OpenShipConfig()



    def RunRefiningProcess(self, refineryID):
        eve.GetInventoryFromId(refineryID).RunRefiningProcess()



    def OpenDrones(self):
        if getattr(self, '_openingDrones', 0):
            return 
        self._openingDrones = 1
        uthread.new(self._OpenDrones)



    def _OpenDrones(self):
        try:
            sm.StartService('window').OpenDrones(eve.session.shipid, 'My')

        finally:
            self._openingDrones = 0




    def EnterPOSPassword(self):
        sm.StartService('pwn').EnterShipPassword()



    def EnterForceFieldPassword(self, towerID):
        sm.StartService('pwn').EnterTowerPassword(towerID)



    def Eject(self):
        if (eve.Message('ConfirmEject', {}, uix.YESNO) == uix.ID_YES):
            ship = sm.StartService('gameui').GetShipAccess()
            if ship:
                if session.stationid:
                    eve.Message('NoEjectingToSpaceInStation')
                else:
                    self.LogNotice('Ejecting from ship', session.shipid)
                    sm.StartService('sessionMgr').PerformSessionChange('eject', ship.Eject)



    def Board(self, id):
        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            self.LogNotice('Boarding ship', id)
            sm.StartService('sessionMgr').PerformSessionChange('board', ship.Board, id, (session.shipid or session.stationid))
            shipItem = sm.StartService('godma').GetItem(eve.session.shipid)
            if (shipItem and (shipItem.groupID != const.groupRookieship)):
                sm.StartService('tutorial').OpenTutorialSequence_Check(uix.insuranceTutorial)



    def BoardSMAShip(self, structureID, shipID):
        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            self.LogNotice('Boarding SMA ship', structureID, shipID)
            sm.StartService('sessionMgr').PerformSessionChange('board', ship.BoardStoredShip, structureID, shipID)
            shipItem = sm.StartService('godma').GetItem(eve.session.shipid)
            if (shipItem and (shipItem.groupID != const.groupRookieship)):
                sm.StartService('tutorial').OpenTutorialSequence_Check(uix.insuranceTutorial)



    def ToggleAutopilot(self, on):
        if on:
            sm.StartService('autoPilot').SetOn()
        else:
            sm.StartService('autoPilot').SetOff('toggled through menu')



    def SelfDestructShip(self, pickid):
        if (eve.Message('ConfirmSelfDestruct', {}, uix.YESNO) == uix.ID_YES):
            ship = sm.StartService('gameui').GetShipAccess()
            if (ship and (not session.stationid)):
                self.LogNotice('Self Destruct for', session.shipid)
                sm.StartService('sessionMgr').PerformSessionChange('selfdestruct', ship.SelfDestruct, pickid)



    def SetParent(self, pickid):
        sm.GetService('camera').SetCameraParent(pickid)



    def SetInterest(self, pickid):
        sm.GetService('camera').SetCameraInterest(pickid)



    def TryLookAt(self, itemID):
        slimItem = uix.GetBallparkRecord(itemID)
        if not slimItem:
            return 
        try:
            sm.GetService('camera').LookAt(itemID)
        except Exception, e:
            sys.exc_clear()



    def ToggleLookAt(self, itemID):
        if ((sm.GetService('camera').LookingAt() == itemID) and (itemID != eve.session.shipid)):
            self.TryLookAt(session.shipid)
        else:
            self.TryLookAt(itemID)



    def Scoop(self, objectID, typeID, password = None):
        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            toFactionID = sm.StartService('faction').GetFactionOfSolarSystem(eve.session.solarsystemid)
            stuff = self.GetIllegality(objectID, typeID)
            if (stuff and (eve.Message('ConfirmScoopWithIllicitGoods', {'faction': cfg.eveowners.Get(toFactionID).name}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES)):
                return 
            try:
                if (password is None):
                    ship.Scoop(objectID)
                else:
                    ship.Scoop(objectID, password)
            except UserError, what:
                if (what.args[0] == 'ShpScoopSecureCC'):
                    if password:
                        caption = mls.UI_GENERIC_INCORRECTPASSWORD
                        label = mls.UI_GENERIC_PLEASETRYAGAIN
                    else:
                        caption = mls.UI_GENERIC_PASSWORDREQUIRED
                        label = mls.UI_GENERIC_PLEASEENTERPASSWORD
                    passw = uix.NamePopup(caption=caption, label=label, setvalue='', icon=-1, modal=1, btns=None, maxLength=50, passwordChar='*')
                    if passw:
                        self.Scoop(objectID, password=passw['name'])
                else:
                    raise 
                sys.exc_clear()



    def ScoopSMA(self, objectID):
        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            ship.ScoopToSMA(objectID)



    def InteractWithAgent(self, agentID, *args):
        sm.StartService('agents').InteractWith(agentID)



    def TakeOutTrash(self, invItems, *args):
        eve.GetInventory(const.containerHangar).TakeOutTrash([ invItem.itemID for invItem in invItems ])



    def QuickBuy(self, typeID):
        sm.StartService('marketutils').Buy(typeID)



    def QuickSell(self, invItem):
        sm.StartService('marketutils').Sell(invItem.typeID, invItem=invItem)



    def QuickContract(self, invItems, *args):
        sm.GetService('contracts').OpenCreateContract(items=invItems)



    def ShowMarketDetails(self, invItem):
        uthread.new(sm.StartService('marketutils').ShowMarketDetails, invItem.typeID, None)



    def GetContainerContents(self, invItem):
        hasFlag = (invItem.categoryID == const.categoryShip)
        name = cfg.invtypes.Get(invItem.typeID).name
        stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
        self.DoGetContainerContents(invItem.itemID, stationID, hasFlag, name)



    def DoGetContainerContents(self, itemID, stationID, hasFlag, name):
        contents = eve.inventorymgr.GetContainerContents(itemID, stationID)
        t = ''
        lst = []
        for c in contents:
            locationName = ''
            flag = c.flagID
            if (flag == const.flagPilot):
                continue
            locationName = util.GetShipFlagLocationName(flag)
            t = cfg.invtypes.Get(c.typeID)
            if hasFlag:
                txt = ('%s<t>%s<t>%s<t>%s' % (t.name,
                 cfg.invgroups.Get(t.groupID).name,
                 locationName,
                 c.stacksize))
            else:
                txt = ('%s<t>%s<t>%s' % (t.name,
                 cfg.invgroups.Get(t.groupID).name,
                 c.stacksize))
            lst.append([txt,
             None,
             c.typeID])

        if hasFlag:
            hdr = [mls.UI_GENERIC_NAME,
             mls.UI_GENERIC_GROUP,
             mls.UI_GENERIC_LOCATION,
             mls.UI_GENERIC_QTY]
        else:
            hdr = [mls.UI_GENERIC_NAME,
             mls.UI_GENERIC_GROUP,
             mls.UI_GENERIC_QTY]
        uix.ListWnd(lst, 'item', mls.UI_GENERIC_ITEMSINCONTAINER, hint=(mls.UI_GENERIC_ITEMSINCONTAINER_HINT % {'name': name}), isModal=0, minChoices=0, scrollHeaders=hdr, minw=500)



    def AddToQuickBar(self, typeID):
        current = settings.user.ui.Get('quickbar', {})
        lastid = settings.user.ui.Get('quickbar_lastid', 0)
        for (id, data,) in current.items():
            if ((data.parent == 0) and (data.label == typeID)):
                return 

        n = util.KeyVal()
        n.parent = 0
        n.id = (lastid + 1)
        n.label = typeID
        lastid += 1
        settings.user.ui.Set('quickbar_lastid', lastid)
        current[n.id] = n
        settings.user.ui.Set('quickbar', current)
        sm.ScatterEvent('OnMarketQuickbarChange', menu=1)



    def RemoveFromQuickBar(self, node):
        current = settings.user.ui.Get('quickbar', {})
        parent = node.parent
        typeID = node.typeID
        toDelete = None
        for (id, data,) in current.items():
            if ((parent == data.parent) and (type(data.label) == types.IntType)):
                if (data.label == typeID):
                    toDelete = id
                    break

        if toDelete:
            del current[id]
        settings.user.ui.Set('quickbar', current)
        sm.ScatterEvent('OnMarketQuickbarChange')



    def GetAndvancedMarket(self, typeID):
        return 



    def ActivateShip(self, invItem):
        if (invItem.singleton and (not eve.triapp.uilib.Key(uix.VK_CONTROL))):
            sm.StartService('station').TryActivateShip(invItem)



    def LeaveShip(self, invItem):
        if (invItem.singleton and (not eve.triapp.uilib.Key(uix.VK_CONTROL))):
            sm.StartService('station').TryLeaveShip(invItem)



    def StripFitting(self, invItem):
        if (eve.Message('AskStripShip', None, uix.YESNO, suppress=uix.ID_YES) == uix.ID_YES):
            shipID = invItem.itemID
            sm.GetService('invCache').GetInventoryFromId(shipID).StripFitting()



    def ExitStation(self, invItem):
        uicore.cmd.CmdExitStation()



    def CheckLocked(self, func, invItemsOrIDs):
        if not len(invItemsOrIDs):
            return 
        else:
            if ((type(invItemsOrIDs[0]) == int) or (not hasattr(invItemsOrIDs[0], 'itemID'))):
                ret = func(invItemsOrIDs)
            else:
                lockedItems = []
                try:
                    for item in invItemsOrIDs:
                        if sm.StartService('invCache').IsItemLocked(item.itemID):
                            continue
                        if sm.StartService('invCache').TryLockItem(item.itemID):
                            lockedItems.append(item)

                    if not len(lockedItems):
                        eve.Message('BusyItems')
                        return 
                    ret = func(lockedItems)

                finally:
                    for invItem in lockedItems:
                        sm.StartService('invCache').UnlockItem(invItem.itemID)


            return ret



    def Repackage(self, invItems):
        if (eve.Message('ConfirmRepackageItem', {}, uix.YESNO) != uix.ID_YES):
            return 
        validIDsByStationID = defaultdict(list)
        ok = 0
        for invItem in invItems:
            state = sm.StartService('godma').GetItem(invItem.itemID)
            if state:
                damage = 0
                if (invItem.categoryID in (const.categoryShip, const.categoryDrone)):
                    damage += state.armorDamage
                damage += state.damage
                if (damage != 0):
                    eve.Message('CantRepackageDamagedItem')
            contracts = sm.StartService('insurance').GetContracts()
            if contracts.has_key(invItem.itemID):
                if (ok or (eve.Message('RepairUnassembleVoidsContract', {}, uix.YESNO) == uix.ID_YES)):
                    stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
                    if (stationID is not None):
                        validIDsByStationID[stationID].append((invItem.itemID, invItem.locationID))
                        ok = 1
                else:
                    continue
            else:
                stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
                if (stationID is not None):
                    validIDsByStationID[stationID].append((invItem.itemID, invItem.locationID))
                else:
                    continue
                    stationID = sm.StartService('invCache').GetStationIDOfItem(invItem)
                    if (stationID is not None):
                        validIDsByStationID[stationID].append((invItem.itemID, invItem.locationID))

        skipChecks = []
        while True:
            try:
                sm.RemoteSvc('repairSvc').UnasembleItems(dict(validIDsByStationID), skipChecks)
            except UserError, e:
                if (cfg.messages[e.msg].messageType == 'question'):
                    ret = eve.Message(e.msg, e.dict, uix.YESNO)
                    if (ret == uix.ID_YES):
                        skipChecks.append(e.msg)
                        sys.exc_clear()
                        continue
                else:
                    raise 
            break




    def Break(self, invItems):
        ok = 0
        validIDs = []
        for invItem in invItems:
            if (ok or (eve.Message('ConfirmBreakCourierPackage', {}, uix.OKCANCEL) == uix.ID_OK)):
                validIDs.append(invItem.itemID)
                ok = 1

        for itemID in validIDs:
            eve.GetInventoryFromId(itemID).BreakPlasticWrap()




    def DeliverCourierContract(self, invItem):
        sm.GetService('contracts').DeliverCourierContractFromItemID(invItem.itemID)



    def FindCourierContract(self, invItem):
        sm.GetService('contracts').FindCourierContractFromItemID(invItem.itemID)



    def LaunchDrones(self, invItems, *args):
        sm.GetService('godma').GetStateManager().SendDroneSettings()
        util.LaunchFromShip(invItems)



    def LaunchForSelf(self, invItems):
        util.LaunchFromShip(invItems, session.charid)



    def LaunchForCorp(self, invItems, ignoreWarning = False):
        util.LaunchFromShip(invItems, session.corpid, ignoreWarning)



    def LaunchSMAContents(self, invItems):
        if (type(invItems) is not list):
            invItems = [invItems]
        structureID = None
        bp = sm.StartService('michelle').GetBallpark()
        myShipBall = bp.GetBall(session.shipid)
        if (myShipBall and (myShipBall.mode == destiny.DSTBALL_WARP)):
            raise UserError('ShipInWarp')
        ids = []
        for invItem in invItems:
            structureID = invItem.locationID
            ids += ([invItem.itemID] * invItem.stacksize)

        sm.StartService('gameui').GetShipAccess().LaunchFromContainer(structureID, ids)



    def Jettison(self, invItems):
        if (eve.Message('ConfirmJettison', {}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
            return 
        ids = []
        for invItem in invItems:
            ids += [invItem.itemID]

        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            ship.Jettison(ids)



    def TrashInvItems(self, invItems):
        if (len(invItems) == 0):
            return 
        self.CheckItemsInSamePlace(invItems)
        if (len(invItems) == 1):
            question = 'ConfirmTrashingSin'
            args = {'item': (TYPEIDANDQUANTITY,
                      invItems[0].typeID,
                      invItems[0].stacksize)}
        else:
            question = 'ConfirmTrashingPlu'
            report = ''
            for item in invItems:
                report += ('<t>- %s<br>' % cfg.FormatConvert(TYPEIDANDQUANTITY, item.typeID, item.stacksize))

            args = {'items': report}
        if (eve.Message(question, args, uix.YESNO) != uix.ID_YES):
            return 
        stationID = sm.StartService('invCache').GetStationIDOfItem(invItems[0])
        windows = ['sma',
         'corpHangar',
         'drones',
         'shipCargo']
        for item in invItems:
            isShip = False
            if hasattr(item, 'categoryID'):
                isShip = (item.categoryID == const.categoryShip)
            else:
                isShip = (cfg.invtypes.Get(item.typeID).categoryID == const.categoryShip)
            if isShip:
                for window in windows:
                    wnd = sm.GetService('window').GetWindow(('%s_%s' % (window, item.itemID)))
                    if wnd:
                        wnd.SelfDestruct()


        errors = eve.inventorymgr.TrashItems([ item.itemID for item in invItems ], (stationID if stationID else invItems[0].locationID))
        if errors:
            for e in errors:
                eve.Message(e)

            return 
        isCorp = (invItems[0].ownerID == eve.session.corpid)
        self.InvalidateItemLocation([session.charid, session.corpid][isCorp], stationID, invItems[0].flagID)
        if isCorp:
            sm.ScatterEvent('OnCorpAssetChange', invItems, stationID)



    def Refine(self, invItems):
        if not eve.session.stationid:
            return 
        if (len(invItems) == 1):
            item = invItems[0]
            ty = cfg.invtypes.Get(item.typeID)
            if (item.stacksize < ty.portionSize):
                eve.Message('QuantityLessThanMinimumPortion', {'typename': ty.name,
                 'portion': ty.portionSize})
                return 
        sm.StartService('reprocessing').ReprocessDlg(invItems)



    def RefineToHangar(self, invItems):
        if not eve.session.stationid:
            return 
        (ownerID, flag,) = (invItems[0].ownerID, invItems[0].flagID)
        if (flag not in (const.flagHangar,
         const.flagCorpSAG2,
         const.flagCorpSAG3,
         const.flagCorpSAG4,
         const.flagCorpSAG5,
         const.flagCorpSAG6,
         const.flagCorpSAG7)):
            flag = const.flagHangar
        if ((flag != const.flagHangar) and (ownerID != eve.session.corpid)):
            ownerID = eve.session.corpid
        if (ownerID not in (eve.session.charid, eve.session.corpid)):
            ownerID = eve.session.charid
        sm.StartService('reprocessing').ReprocessDlg(invItems, ownerID, flag)



    def TrainNow(self, invItems):
        if (len(invItems) > 1):
            eve.Message('TrainMoreTheOne')
            return 
        self.InjectSkillIntoBrain(invItems)
        blue.pyos.synchro.Sleep(500)
        sm.StartService('skillqueue').TrainSkillNow(invItems[0].typeID, 1)



    def InjectSkillIntoBrain(self, invItems):
        sm.StartService('skills').InjectSkillIntoBrain(invItems)



    def PlugInImplant(self, invItems):
        if (eve.Message('ConfirmPlugInImplant', {}, uix.OKCANCEL) != uix.ID_OK):
            return 
        for invItem in invItems:
            sm.StartService('godma').GetSkillHandler().CharAddImplant(invItem.itemID, invItem.locationID)




    def ApplyPilotLicence(self, itemID):
        try:
            sm.RemoteSvc('userSvc').ApplyPilotLicence(itemID, justQuery=True)
        except UserError, e:
            if (e.msg == '28DaysConfirmApplyServer'):
                if (eve.Message(e.msg, e.dict, uix.YESNO) != uix.ID_YES):
                    return 
                sm.RemoteSvc('userSvc').ApplyPilotLicence(itemID, justQuery=False)
            else:
                raise 



    def ConsumeBooster(self, invItems):
        if (type(invItems) is not list):
            invItems = [invItems]
        for invItem in invItems:
            sm.StartService('godma').GetSkillHandler().CharUseBooster(invItem.itemID, invItem.locationID)




    def AssembleContainer(self, invItems):
        for invItem in invItems:
            eve.inventorymgr.AssembleCargoContainer(invItem.itemID, None, 0.0)




    def OpenContainer(self, invItems):
        for invItem in invItems:
            if (invItem.ownerID not in (eve.session.charid, eve.session.corpid)):
                eve.Message('CantDoThatWithSomeoneElsesStuff')
                return 
            name = (cfg.evelocations.Get(invItem.itemID).name or cfg.invtypes.Get(invItem.typeID).name)
            sm.StartService('window').OpenContainer(invItem.itemID, name, ("%s's container" % name), invItem.typeID, hasCapacity=(invItem.typeID != const.typePlasticWrap))




    def Manufacture(self, invItems, activityID):
        sm.StartService('manufacturing').CreateJob(invItems, None, activityID)



    def AssembleShip(self, invItems):
        itemIDs = []
        for item in invItems:
            techLevel = sm.StartService('godma').GetTypeAttribute(invItems[0].typeID, const.attributeTechLevel)
            if (techLevel is None):
                techLevel = 1
            else:
                techLevel = int(techLevel)
            if (techLevel == 3):
                if (session.stationid is None):
                    eve.Message('CantAssembleModularShipInSpace')
                    return 
                windowSvc = sm.GetService('window')
                wndName = ('assembleWindow_%s' % item.itemID)
                wnd = windowSvc.GetWindow(wndName)
                if (wnd is None):
                    wnd = windowSvc.GetWindow(wndName, create=1, decoClass=form.AssembleShip, ship=invItems[0])
                else:
                    wnd.Maximize()
                return 
            itemIDs.append(item.itemID)

        sm.StartService('gameui').GetShipAccess().AssembleShip(itemIDs)



    def TryFit(self, invItems):
        if not eve.session.shipid:
            return 
        godma = sm.services['godma']
        ship = godma.GetItem(eve.session.shipid)
        if not ship:
            return 
        godmaSM = godma.GetStateManager()
        invCassi = sm.StartService('invCache')
        useRigs = None
        shipInv = eve.GetInventoryFromId(eve.session.shipid)
        charges = set()
        for invItem in invItems[:]:
            if (invItem.categoryID == const.categoryModule):
                moduleEffects = cfg.dgmtypeeffects.get(invItem.typeID, [])
                for mEff in moduleEffects:
                    if (mEff.effectID == const.effectRigSlot):
                        if (useRigs is None):
                            useRigs = (True if self.RigFittingCheck(invItem) else False)
                        if not useRigs:
                            invItems.remove(invItem)
                            invCassi.UnlockItem(invItem.itemID)
                            break

            elif (invItem.categoryID == const.categorySubSystem):
                if godmaSM.CheckFutileSubSystemSwitch(invItem.typeID, invItem.itemID):
                    invItems.remove(invItem)
                    invCassi.UnlockItem(invItem.itemID)
            else:
                if (invItem.categoryID == const.categoryCharge):
                    charges.add(invItem)
                    invItems.remove(invItem)

        if (len(invItems) > 0):
            ship.inventory.moniker.MultiAdd([ invItem.itemID for invItem in invItems ], invItems[0].locationID, flag=const.flagAutoFit)
            for invItem in invItems:
                uthread.new(godma.GetStateManager().DelayedOnlineAttempt, session.shipid, invItem.itemID)

        if charges:
            if len(invItems):
                count = 0
                while (count < 1000):
                    count += 1
                    blue.pyos.synchro.Sleep(100)
                    for item in invItems:
                        if godmaSM.GetAttributeValueByID(item.itemID, const.attributeIsOnline):
                            continue
                        if ((count % 20) == 0):
                            self.LogInfo('After', (count / 10), "seconds, I'm still waiting for all modules to come online")
                        break
                        continue
                    else:
                        break

                else:
                    self.LogWarn("I've waited for", (count / 10), "seconds for all the added modules to come online, but they didn't. Continuing, but expect errors...")

            shipStuff = shipInv.List()
            shipStuff.sort(key=lambda r: (r.flagID, godmaSM.IsSubLocation(r.itemID)))
            loadedSlots = set()
        for invItem in charges:
            chargeDgmType = godmaSM.GetType(invItem.typeID)
            isCrystalOrScript = (invItem.groupID in cfg.GetCrystalGroups())
            for row in shipStuff:
                if (row in loadedSlots):
                    continue
                if not cfg.IsShipFittingFlag(row.flagID):
                    continue
                if (godmaSM.IsInWeaponBank(row.itemID) and godmaSM.IsSlaveModule(row.itemID)):
                    continue
                if (row.categoryID == const.categoryCharge):
                    continue
                moduleDgmType = godmaSM.GetType(row.typeID)
                desiredSize = getattr(moduleDgmType, 'chargeSize', None)
                for x in xrange(1, 5):
                    chargeGroup = getattr(moduleDgmType, ('chargeGroup%d' % x), False)
                    if not chargeGroup:
                        continue
                    if (chargeDgmType.groupID != chargeGroup):
                        continue
                    if ((desiredSize is not None) and (getattr(chargeDgmType, 'chargeSize', -1) != desiredSize)):
                        continue
                    leftOvers = False
                    for (i, squatter,) in enumerate([ i for i in shipStuff if (i.flagID == row.flagID) ]):
                        if (isCrystalOrScript and (i > 0)):
                            break
                        else:
                            if ((not isCrystalOrScript) and godmaSM.IsSubLocation(squatter.itemID)):
                                if (godmaSM.GetType(row.typeID).capacity <= (chargeDgmType.volume * squatter.stacksize)):
                                    break
                    else:
                        godmaSM.LoadAmmoToModules([row.itemID], invItem.typeID, invItem.itemID, invItem.locationID)
                        leftOvers = ((not isCrystalOrScript) and (invItem.stacksize > (godmaSM.GetType(row.typeID).capacity / chargeDgmType.volume)))
                        loadedSlots.add(row)
                        blue.pyos.synchro.Sleep(100)
                        break


                continue
                if leftOvers:
                    continue
                break
                continue
            else:
                eve.Message('NoSuitableModules')





    def OpenCargohold(self, invItems):
        knowCantDoThatWithSomeoneElsesStuff = 0
        for invItem in invItems:
            if not (invItem.ownerID == eve.session.charid):
                if not knowCantDoThatWithSomeoneElsesStuff:
                    eve.Message('CantDoThatWithSomeoneElsesStuff')
                    knowCantDoThatWithSomeoneElsesStuff = 1
                else:
                    continue
            name = cfg.evelocations.Get(invItem.itemID).name
            sm.StartService('window').OpenCargo(invItem.itemID, name, ("%s's %s" % (name, mls.UI_GENERIC_CARGO)), invItem.typeID)




    def OpenDroneBay(self, invItems):
        knowCantDoThatWithSomeoneElsesStuff = 0
        for invItem in invItems:
            if not (invItem.ownerID == eve.session.charid):
                if not knowCantDoThatWithSomeoneElsesStuff:
                    eve.Message('CantDoThatWithSomeoneElsesStuff')
                    knowCantDoThatWithSomeoneElsesStuff = 1
                return 
            name = cfg.evelocations.Get(invItem.itemID).name
            sm.StartService('window').OpenDrones(invItem.itemID, name, ("%s's %s" % (name, mls.UI_GENERIC_DRONEBAY)), invItem.typeID)




    def OpenSpecialCargoBay(self, id, invFlag):
        if getattr(self, '_openingSpecialCargo', 0):
            return 
        self._openingSpecialCargo = 1
        uthread.new(self._OpenSpecialCargoBay, id, invFlag)



    def _OpenSpecialCargoBay(self, id, invFlag):
        try:
            invFlagData = inventoryFlagsCommon.inventoryFlagData[invFlag]
            if (id == eve.session.shipid):
                holdName = (mls.UI_GENERIC_MYSPECIALBAY % invFlagData['name'])
            else:
                holdName = (mls.UI_GENERIC_POSSESSIVESPECIALBAY % {'owner': uix.Possessive(cfg.evelocations.Get(id).name),
                 'item': invFlagData['name']})
            sm.StartService('window').OpenSpecialCargoBay(id, holdName, invFlag, nameLabel='specialCargo')

        finally:
            self._openingSpecialCargo = 0




    def HandleMultipleCallError(self, droneID, ret, messageName):
        if not len(ret):
            return 
        if (len(droneID) == 1):
            pick = droneID[0]
            raise UserError(ret[pick][0], ret[pick][1])
        elif (len(droneID) >= len(ret)):
            lastError = ''
            for error in ret.itervalues():
                if ((error[0] != lastError) and (lastError != '')):
                    raise UserError(messageName, {'succeeded': (len(droneID) - len(ret)),
                     'failed': len(ret),
                     'total': len(droneID)})
                lastError = error[0]
            else:
                pick = ret.items()[0][1]
                raise UserError(pick[0], pick[1])




    def EngageTarget(self, droneIDs):
        michelle = sm.StartService('michelle')
        requiresAttackConfirmation = False
        requiresAidConfirmation = False
        dronesRemoved = []
        for droneID in droneIDs:
            item = michelle.GetItem(droneID)
            if not item:
                dronesRemoved.append(droneID)
                continue
            for row in cfg.dgmtypeeffects.get(item.typeID, []):
                (effectID, isDefault,) = (row.effectID, row.isDefault)
                if isDefault:
                    effect = cfg.dgmeffects.Get(effectID)
                    if effect.isOffensive:
                        requiresAttackConfirmation = True
                        break
                    else:
                        if effect.isAssistance:
                            requiresAidConfirmation = True
                            break


        for droneID in dronesRemoved:
            droneIDs.remove(droneID)

        if (requiresAttackConfirmation and requiresAidConfirmation):
            raise UserError('DroneCommandEngageRequiresNoAmbiguity')
        targetID = sm.StartService('target').GetActiveTargetID()
        if (targetID is None):
            raise UserError('DroneCommandRequiresActiveTarget')
        if (requiresAidConfirmation and (not sm.StartService('consider').DoAidConfirmations(targetID))):
            return 
        if (requiresAttackConfirmation and (not sm.StartService('consider').DoAttackConfirmations(targetID))):
            return 
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdEngage(droneIDs, targetID)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')
            if droneIDs:
                name = sm.GetService('space').GetWarpDestinationName(targetID)
                eve.Message('Command', {'command': (mls.UI_INFLIGHT_DRONESENGAGING % {'name': name})})



    def ReturnControl(self, droneIDs):
        michelle = sm.StartService('michelle')
        dronesByOwner = {}
        for droneID in droneIDs:
            ownerID = michelle.GetDroneState(droneID).ownerID
            if dronesByOwner.has_key(ownerID):
                dronesByOwner[ownerID].append(droneID)
            else:
                dronesByOwner[ownerID] = [droneID]

        entity = moniker.GetEntityAccess()
        if entity:
            for (ownerID, IDs,) in dronesByOwner.iteritems():
                ret = entity.CmdRelinquishControl(IDs)
                self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')




    def DelegateControl(self, charID, droneIDs):
        if (charID is None):
            targetID = sm.StartService('target').GetActiveTargetID()
            if (targetID is None):
                raise UserError('DroneCommandRequiresActiveTarget')
            michelle = sm.StartService('michelle')
            targetItem = michelle.GetItem(targetID)
            if ((targetItem.categoryID != const.categoryShip) or (targetItem.groupID == const.groupCapsule)):
                raise UserError('DroneCommandRequiresShipButNotCapsule')
            targetBall = michelle.GetBall(targetID)
            if ((not targetBall.isInteractive) or (not sm.GetService('fleet').IsMember(targetItem.ownerID))):
                raise UserError('DroneCommandRequiresShipPilotedFleetMember')
            controllerID = targetItem.ownerID
        else:
            controllerID = charID
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdDelegateControl(droneIDs, controllerID)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def Assist(self, charID, droneIDs):
        if (charID is None):
            targetID = sm.StartService('target').GetActiveTargetID()
            if (targetID is None):
                raise UserError('DroneCommandRequiresActiveTarget')
            michelle = sm.StartService('michelle')
            targetItem = michelle.GetItem(targetID)
            if ((targetItem.categoryID != const.categoryShip) or (targetItem.groupID == const.groupCapsule)):
                raise UserError('DroneCommandRequiresShipButNotCapsule')
            targetBall = michelle.GetBall(targetID)
            if ((not targetBall.isInteractive) or (not sm.GetService('fleet').IsMember(targetItem.ownerID))):
                raise UserError('DroneCommandRequiresShipPilotedFleetMember')
            assistID = targetItem.ownerID
        else:
            assistID = charID
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdAssist(assistID, droneIDs)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def Guard(self, charID, droneIDs):
        if (charID is None):
            targetID = sm.StartService('target').GetActiveTargetID()
            if (targetID is None):
                raise UserError('DroneCommandRequiresActiveTarget')
            michelle = sm.StartService('michelle')
            targetItem = michelle.GetItem(targetID)
            if ((targetItem.categoryID != const.categoryShip) or (targetItem.groupID == const.groupCapsule)):
                raise UserError('DroneCommandRequiresShipButNotCapsule')
            targetBall = michelle.GetBall(targetID)
            if ((not targetBall.isInteractive) or (not sm.GetService('fleet').IsMember(targetItem.ownerID))):
                raise UserError('DroneCommandRequiresShipPilotedFleetMember')
            guardID = targetItem.ownerID
        else:
            guardID = charID
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdGuard(guardID, droneIDs)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def Mine(self, droneIDs):
        targetID = sm.StartService('target').GetActiveTargetID()
        if (targetID is None):
            raise UserError('DroneCommandRequiresActiveTarget')
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdMine(droneIDs, targetID)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def MineRepeatedly(self, droneIDs):
        targetID = sm.StartService('target').GetActiveTargetID()
        if (targetID is None):
            raise UserError('DroneCommandRequiresActiveTarget')
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdMineRepeatedly(droneIDs, targetID)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def DroneUnanchor(self, droneIDs):
        targetID = sm.StartService('target').GetActiveTargetID()
        if (targetID is None):
            raise UserError('DroneCommandRequiresActiveTarget')
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdUnanchor(droneIDs, targetID)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def ReturnAndOrbit(self, droneIDs):
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdReturnHome(droneIDs)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def ReturnToDroneBay(self, droneIDs):
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdReturnBay(droneIDs)
            self.HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')



    def ScoopToDroneBay(self, objectIDs):
        ship = sm.StartService('gameui').GetShipAccess()
        if ship:
            ret = ship.ScoopDrone(objectIDs)
            self.HandleMultipleCallError(objectIDs, ret, 'MultiDroneCmdResult')



    def FitDrone(self, invItems):
        if (type(invItems) is not list):
            invItems = [invItems]
        itemIDs = [ node.itemID for node in invItems ]
        if eve.session.shipid:
            for itemID in itemIDs:
                sm.StartService('invCache').UnlockItem(itemID)

            eve.GetInventoryFromId(eve.session.shipid).MultiAdd(itemIDs, invItems[0].locationID, flag=const.flagDroneBay)



    def AbandonDrone(self, droneIDs):
        if (eve.Message('ConfirmAbandonDrone', {}, uix.YESNO, suppress=uix.ID_YES) != uix.ID_YES):
            return 
        entity = moniker.GetEntityAccess()
        if entity:
            ret = entity.CmdAbandonDrone(droneIDs)
            self.HandleMultipleCallError(droneIDs, ret, 'MultDroneCmdResult')



    def CopyItemIDAndMaybeQuantityToClipboard(self, invItem):
        txt = str(invItem.itemID)
        if (invItem.stacksize > 1):
            txt += ('(%s)' % invItem.stacksize)
        blue.pyos.SetClipboardData(txt)



    def ItemLockFunction(self, invItem, *args):
        sm.StartService('invCache').TryLockItem(invItem.itemID, 'lockItemMenuFunction', {'itemType': cfg.invtypes.Get(invItem.typeID).typeName,
         'action': args[0]}, 1)
        try:
            return args[1](*((), args[-1])[(len(args) > 2)])

        finally:
            sm.StartService('invCache').UnlockItem(invItem.itemID)




    def SetName(self, invItemsOrSlimItems):
        for invItem in invItemsOrSlimItems:
            cfg.evelocations.Prime([invItem.itemID])
            try:
                setval = cfg.evelocations.Get(invItem.itemID).name
            except:
                setval = ''
                sys.exc_clear()
            myShip = 0
            maxLength = 100
            setval = setval[:32]
            categoryID = cfg.invtypes.Get(invItem.typeID).Group().Category().id
            if (categoryID == const.categoryShip):
                maxLength = 20
            if (categoryID == const.categoryStructure):
                maxLength = 32
            nameRet = uix.NamePopup(mls.UI_GENERIC_SETNAME, mls.UI_GENERIC_TYPEINNEWNAME, setvalue=setval, maxLength=maxLength)
            if nameRet:
                eve.inventorymgr.SetLabel(invItem.itemID, nameRet['name'].replace('\n', ' '))
                sm.ScatterEvent('OnItemNameChange')




    def AskNewContainerPwd(self, invItems, desc, which = 1):
        for invItem in invItems:
            self.AskNewContainerPassword(invItem.itemID, desc, which)




    def GetGlobalActiveItemKeyName(self, forWhat):
        key = None
        if (forWhat in [mls.UI_CMD_ORBIT,
         mls.UI_CMD_KEEPATRANGE,
         self.DefaultWarpToLabel()[0]]):
            key = ['Orbit',
             'KeepAtRange',
             'WarpTo'][[mls.UI_CMD_ORBIT,
             mls.UI_CMD_KEEPATRANGE,
             self.DefaultWarpToLabel()[0]].index(forWhat)]
        return key



    def GetDefaultActionDistance(self, what):
        if (what == 'KeepAtRange'):
            return int(settings.user.ui.Get('defaultKeepAtRangeDist', 500))
        if (what == 'Orbit'):
            return int(settings.user.ui.Get('defaultOrbitDist', 5000))
        if (what == 'WarpTo'):
            return settings.user.ui.Get('defaultWarpToDist', const.minWarpEndDistance)



    def CopyCoordinates(self, itemID):
        ball = self.michelle.GetBall(itemID)
        if ball:
            blue.pyos.SetClipboardData(str((ball.x,
             ball.y,
             ball.z)))



    def RepairItems(self, items):
        if ((items is None) or (len(items) < 1)):
            return 
        wnd = sm.GetService('window').GetWindow('repairshop', decoClass=form.RepairShopWindow, create=1, maximize=1)
        if (wnd and (not wnd.destroyed)):
            wnd.DisplayRepairQuote(items)



    def AnchorOrbital(self, itemID):
        posMgr = moniker.GetPOSMgr()
        posMgr.AnchorOrbital(itemID)



    def UnanchorOrbital(self, itemID):
        posMgr = moniker.GetPOSMgr()
        posMgr.UnanchorOrbital(itemID)



    def OnlineOrbital(self, itemID):
        posMgr = moniker.GetPOSMgr()
        posMgr.OnlineOrbital(itemID)



    def OfflineOrbital(self, itemID):
        posMgr = moniker.GetPOSMgr()
        posMgr.OfflineOrbital(itemID)




class ActionMenu(uicls.Container):
    __guid__ = 'xtriui.ActionMenu'

    def init(self):
        self.actionMenuOptions = {mls.UI_CMD_SHOWINFO: ('ui_44_32_24', 0, 0, 0, 0),
         mls.UI_CMD_LOCKTARGET: ('ui_44_32_17', 0, 0, 0, 0),
         mls.UI_CMD_UNLOCKTARGET: ('ui_44_32_17', 0, 0, 0, 1),
         mls.UI_CMD_APPROACH: ('ui_44_32_23', 0, 0, 0, 0),
         mls.UI_CMD_LOOKAT: ('ui_44_32_20', 0, 0, 0, 0),
         mls.UI_CMD_RESETCAMERA: ('ui_44_32_20', 0, 0, 0, 1),
         mls.UI_CMD_KEEPATRANGE: ('ui_44_32_22', 0, 0, 1, 0),
         mls.UI_CMD_ORBIT: ('ui_44_32_21', 0, 0, 1, 0),
         mls.UI_CMD_DOCK: ('ui_44_32_9', 0, 0, 0, 0),
         mls.UI_CMD_STARTCONVERSATION: ('ui_44_32_33', 0, 0, 0, 0),
         mls.UI_CMD_OPENCARGO: ('ui_44_32_35', 0, 0, 0, 0),
         mls.UI_CMD_OPENMYCARGO: ('ui_44_32_35', 0, 0, 0, 0),
         mls.UI_PI_ACCESSCARGOLINK: ('ui_44_32_35', 0, 0, 0, 0),
         mls.UI_CMD_STOPMYSHIP: ('ui_44_32_38', 0, 0, 0, 0),
         mls.UI_CMD_STOPMYCAPSULE: ('ui_44_32_38', 0, 0, 0, 0),
         mls.UI_CMD_ACTIVATEAUTOPILOT: ('ui_44_32_12', 0, 0, 0, 0),
         mls.UI_CMD_DEACTIVATEAUTOPILOT: ('ui_44_32_12', 0, 0, 0, 1),
         mls.UI_CMD_EJECT: ('ui_44_32_36', 0, 0, 0, 0),
         mls.UI_CMD_SELFDESTRUCT: ('ui_44_32_37', 0, 0, 0, 0),
         mls.UI_CMD_BOARDSHIP: ('ui_44_32_40', 0, 0, 0, 0),
         mls.UI_CMD_JUMP: ('ui_44_32_39', 0, 0, 0, 0),
         mls.UI_CMD_ENTERWORMHOLE: ('ui_44_32_39', 0, 0, 0, 0),
         mls.UI_CMD_ACTIVATEGATE: ('ui_44_32_39', 0, 0, 0, 0),
         mls.UI_CMD_SCOOPTODRONEBAY: ('ui_44_32_1', 0, 0, 0, 0),
         mls.UI_CMD_SCOOPTOCARGOBAY: ('ui_44_32_1', 0, 0, 0, 0),
         mls.UI_CMD_READNEWS: ('ui_44_32_47', 0, 0, 0, 0)}
        self.lastActionSerial = None
        self.sr.actionTimer = None
        self.itemID = None
        self.width = 134
        self.height = 134
        self.pickRadius = -1
        self.oldx = self.oldy = None
        uicore.event.RegisterForTriuiEvents(uix.UI_MOUSEUP, self.OnGlobalUp)
        self.mouseMoveCookie = uicore.event.RegisterForTriuiEvents(uix.UI_MOUSEMOVE, self.OnGlobalMove)



    def Load(self, slimItem, centerItem = None, setposition = 1):
        if not (eve.triapp.uilib.leftbtn or eve.triapp.uilib.midbtn):
            return 
        actions = sm.StartService('menu').CelestialMenu(slimItem.itemID, slimItem=slimItem, showInactive=1, ignoreTypeCheck=1)
        if not (eve.triapp.uilib.leftbtn or eve.triapp.uilib.midbtn):
            return 
        self.itemID = slimItem.itemID
        warptoLabel = sm.GetService('menu').DefaultWarpToLabel()[0]
        warpops = {warptoLabel: ('ui_44_32_18', 0, 0, 1, 0)}
        self.actionMenuOptions.update(warpops)
        serial = ''
        valid = {}
        inactive = None
        for each in actions:
            if each:
                if isinstance(each[0], tuple):
                    name = each[0][0]
                else:
                    name = each[0]
                if (name == 'Inactive'):
                    inactive = each[1]
                else:
                    if (name in self.actionMenuOptions):
                        valid[name] = each
                        if (type(each[1]) not in (str, unicode)):
                            serial += ('%s_' % name)

        if inactive:
            for each in inactive:
                if isinstance(each[0], tuple):
                    name = each[0][0]
                else:
                    name = each[0]
                if (name in self.actionMenuOptions):
                    valid[name] = each
                    if (type(each[1]) not in (str, unicode)):
                        serial += ('%s_' % name)

        if not (eve.triapp.uilib.leftbtn or eve.triapp.uilib.midbtn):
            return 
        if (serial != self.lastActionSerial):
            size = 100
            uix.Flush(self)
            cX = ((size / 2) - 16)
            cY = ((size / 2) - 16)
            i = 0
            order = [mls.UI_CMD_SHOWINFO,
             [mls.UI_CMD_LOCKTARGET, mls.UI_CMD_UNLOCKTARGET],
             [mls.UI_CMD_APPROACH, warptoLabel],
             mls.UI_CMD_ORBIT,
             mls.UI_CMD_KEEPATRANGE]
            default = [None,
             [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
             None]
            groups = {const.groupStation: [None,
                                  [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                  mls.UI_CMD_DOCK],
             const.groupCargoContainer: [None,
                                         [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                         mls.UI_CMD_OPENCARGO],
             const.groupSecureCargoContainer: [None,
                                               [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                               mls.UI_CMD_OPENCARGO],
             const.groupAuditLogSecureContainer: [None,
                                                  [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                                  mls.UI_CMD_OPENCARGO],
             const.groupFreightContainer: [None,
                                           [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                           mls.UI_CMD_OPENCARGO],
             const.groupSpawnContainer: [None,
                                         [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                         mls.UI_CMD_OPENCARGO],
             const.groupDeadspaceOverseersBelongings: [None,
                                                       [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                                       mls.UI_CMD_OPENCARGO],
             const.groupWreck: [None,
                                [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                mls.UI_CMD_OPENCARGO],
             const.groupStargate: [None,
                                   [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                   mls.UI_CMD_JUMP],
             const.groupWormhole: [None,
                                   [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                   mls.UI_CMD_ENTERWORMHOLE],
             const.groupWarpGate: [None,
                                   [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                   mls.UI_CMD_ACTIVATEGATE],
             const.groupBillboard: [None,
                                    [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                    mls.UI_CMD_READNEWS],
             const.groupAgentsinSpace: [mls.UI_CMD_STARTCONVERSATION,
                                        [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                        None],
             const.groupDestructibleAgentsInSpace: [mls.UI_CMD_STARTCONVERSATION,
                                                    [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                                    None],
             const.groupPlanetaryCustomsOffices: [None,
                                                  [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                                  mls.UI_PI_ACCESSCARGOLINK]}
            categories = {const.categoryShip: [mls.UI_CMD_STARTCONVERSATION,
                                  [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                  mls.UI_CMD_BOARDSHIP],
             const.categoryDrone: [None,
                                   [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                                   mls.UI_CMD_SCOOPTODRONEBAY]}
            if (slimItem.itemID == eve.session.shipid):
                order = ([mls.UI_CMD_SHOWINFO,
                 mls.UI_CMD_EJECT,
                 [mls.UI_CMD_STOPMYSHIP, mls.UI_CMD_STOPMYCAPSULE],
                 [mls.UI_CMD_ACTIVATEAUTOPILOT, mls.UI_CMD_DEACTIVATEAUTOPILOT]] + [None,
                 None,
                 [mls.UI_CMD_LOOKAT, mls.UI_CMD_RESETCAMERA],
                 mls.UI_CMD_OPENMYCARGO])
            elif (slimItem.groupID in groups):
                order += groups[slimItem.groupID]
            elif (slimItem.categoryID in categories):
                order += categories[slimItem.categoryID]
            else:
                order += default
            step = (360.0 / 8)
            rad = 48
            angle = 180.0
            for actionName in order:
                if (actionName is None):
                    angle += step
                    i += 1
                    continue
                if (type(actionName) == list):
                    action = None
                    for each in actionName:
                        tryaction = valid.get(each, None)
                        if (tryaction and (type(tryaction[1]) not in (str, unicode))):
                            actionName = each
                            action = tryaction
                            break

                    if (action is None):
                        action = valid.get(actionName[0], (actionName[0], mls.UI_SHARED_NOREASONGIVEN))
                        actionName = actionName[0]
                else:
                    action = valid.get(actionName, (actionName, mls.UI_SHARED_NOREASONGIVEN))
                disabled = (type(action[1]) in (str, unicode))
                props = self.actionMenuOptions[actionName]
                btnpar = xtriui.Action(uicls.Container(parent=self, align=uiconst.TOPLEFT, width=40, height=40, state=uiconst.UI_NORMAL))
                btnpar.left = (int((rad * math.cos(((angle * math.pi) / 180.0)))) + ((self.width - btnpar.width) / 2))
                btnpar.top = (int((rad * math.sin(((angle * math.pi) / 180.0)))) + ((self.height - btnpar.height) / 2))
                btn = blue.os.LoadObject('res:/UI/Component/hudBtn_oval.blue')
                btn.rectLeft = 43
                btn.rectHeight = 40
                btn.rectWidth = 40
                btn.color.a = 1.0
                btn.left = 0
                btn.top = 0
                btnpar.actionID = actionName
                btnpar.name = actionName
                btnpar.action = action
                btnpar.itemIDs = [slimItem.itemID]
                btnpar.killsub = props[3]
                btnpar.pickRadius = -1
                icon = uicls.Icon(icon=props[0], parent=btnpar, pos=(4, 4, 0, 0), align=uiconst.TOPLEFT, idx=0, state=uiconst.UI_DISABLED, hint='')
                if disabled:
                    icon.color.a = 0.5
                    btn.color.a = 0.1
                shadow = icon.CopyTo()
                shadow.left += 1
                shadow.top += 1
                shadow.color.SetRGB(0.0, 0.0, 0.0, 0.5)
                btnpar.children.append(shadow)
                if props[4]:
                    icon = uicls.Icon(icon='ui_44_32_8', parent=btnpar, pos=(5, 5, 0, 0), align=uiconst.TOPLEFT, idx=0, state=uiconst.UI_DISABLED, hint='')
                btnpar.children.append(btn)
                btnpar.PrepareHint()
                angle += step
                i += 1

            self.lastActionSerial = serial
            if (self.sr.actionTimer is None):
                self.sr.actionTimer = base.AutoTimer(1000, self.Load, slimItem, None, 0)
        if centerItem:
            self.left = max(0, min((eve.triapp.uilib.desktop.width - self.width), (centerItem.absoluteLeft - ((self.width - centerItem.width) / 2))))
            self.top = max(0, min((eve.triapp.uilib.desktop.height - self.height), (centerItem.absoluteTop - ((self.height - centerItem.height) / 2))))
        elif setposition:
            self.left = max(0, min((eve.triapp.uilib.desktop.width - self.width), (eve.triapp.uilib.x - (self.width / 2))))
            self.top = max(0, min((eve.triapp.uilib.desktop.height - self.height), (eve.triapp.uilib.y - (self.height / 2))))



    def OnGlobalUp(self, *args):
        if ((not self) or self.destroyed):
            return 
        if (self.itemID and (blue.os.TimeDiffInMs(self.expandTime, blue.os.GetTime()) < 100)):
            sm.StartService('state').SetState(self.itemID, state.selected, 1)
        self.sr.actionTimer = None
        self.sr.updateAngle = None
        mo = eve.triapp.uilib.mouseOver
        self.state = uix.UI_HIDDEN
        self.lastActionSerial = None
        if (mo in self.children):
            uthread.new(mo._OnClick)
        else:
            uix.Flush(uicore.layer.menu)
        if not self.destroyed:
            uicore.event.UnregisterForTriuiEvents(self.mouseMoveCookie)



    def OnGlobalMove(self, *args):
        mo = eve.triapp.uilib.mouseOver
        lib = eve.triapp.uilib
        if not lib.leftbtn:
            self.oldx = self.oldy = None
            return 
        else:
            if (self.oldx and self.oldy):
                (dx, dy,) = ((self.oldx - lib.x), (self.oldy - lib.y))
                camera = sm.GetService('sceneManager').GetRegisteredCamera('default')
                if ((mo.name == 'blocker') and (not lib.rightbtn)):
                    fov = camera.fieldOfView
                    camera.OrbitParent(((-dx * fov) * 0.2), ((dy * fov) * 0.2))
                else:
                    if lib.rightbtn:
                        nav = uix.GetInflightNav(0)
                        if nav:
                            nav.zoomlooking = 1
                        uix.Flush(uicore.layer.menu)
            if (hasattr(self, 'oldx') and hasattr(self, 'oldy')):
                (self.oldx, self.oldy,) = (lib.x, lib.y)
            return 1



    def _OnMouseWheel(self, *args):
        camera = sm.GetService('sceneManager').GetRegisteredCamera('default')
        if (camera.__typename__ == 'EveCamera'):
            camera.Dolly(((-eve.triapp.uilib.dz * 0.001) * abs(camera.translationFromParent.z)))
            camera.translationFromParent.z = sm.StartService('camera').CheckTranslationFromParent(camera.translationFromParent.z)
        return 1




class Action(uicls.Container):
    __guid__ = 'xtriui.Action'

    def init(self):
        self.actionID = None



    def PrepareHint(self, fromWhere = ''):
        if (self and (not self.destroyed)):
            post = ''
            if (type(self.action[1]) in types.StringTypes):
                post = ((' (' + self.action[1]) + ')')
            elif (self.action[0] in [mls.UI_CMD_ORBIT, mls.UI_CMD_KEEPATRANGE]):
                key = sm.GetService('menu').GetGlobalActiveItemKeyName(self.action[0])
                current = sm.GetService('menu').GetDefaultActionDistance(key)
                if (current is not None):
                    post = (' (%s)' % util.FmtDist(current))
                else:
                    post = (' ' + mls.UI_INFLIGHT_NODISTANCESET)
            if hasattr(self, 'cmdName'):
                post += (' [%s]' % uicore.cmd.GetShortcutStringByFuncName(self.cmdName))
            self.sr.hint = (self.actionID.capitalize() + post)



    def GetMenu(self):
        m = []
        if (self.actionID in [mls.UI_CMD_ORBIT,
         mls.UI_CMD_KEEPATRANGE,
         sm.GetService('menu').DefaultWarpToLabel()[0]]):
            m.append(((mls.UI_INFLIGHT_SETDEFAULTDIST % {'typeName': self.actionID}),
             self.SetDefaultDist,
             (self.actionID)))
        return m



    def _OnMouseEnter(self, *args):
        if self.sr.Get('fill', None):
            self.sr.fill.state = uix.UI_DISABLED
            self.sr.fill.color.a = 0.25



    def _OnMouseExit(self, *args):
        if self.sr.Get('fill', None):
            self.sr.fill.state = uix.UI_HIDDEN



    def _OnMouseDown(self, *args):
        if self.sr.Get('fill', None):
            self.sr.fill.color.a = 0.5



    def _OnMouseUp(self, *args):
        if self.sr.Get('fill', None):
            self.sr.fill.color.a = 0.25



    def SetDefaultDist(self, forWhat):
        key = sm.GetService('menu').GetGlobalActiveItemKeyName(forWhat)
        if not key:
            return 
        (minDist, maxDist,) = {mls.UI_CMD_ORBIT: (500, 1000000),
         mls.UI_CMD_KEEPATRANGE: (50, 1000000),
         sm.GetService('menu').DefaultWarpToLabel()[0]: (const.minWarpEndDistance, const.maxWarpEndDistance)}.get(forWhat, (500, 1000000))
        current = sm.GetService('menu').GetDefaultActionDistance(key)
        current = (current or '')
        hint = (mls.UI_INFLIGHT_SETDEFAULTDISTHINT % {'typeName': forWhat,
         'fromDist': util.FmtAmt(minDist),
         'toDist': util.FmtAmt(maxDist)})
        r = uix.QtyPopup(maxvalue=maxDist, minvalue=minDist, setvalue=current, hint=hint, caption=(mls.UI_SHARED_SETDEFDISTANCE % {'type': forWhat}), label=None, digits=0)
        if r:
            range = max(minDist, min(maxDist, r['qty']))
            settings.user.ui.Set(('default%sDist' % key), range)
            sm.ScatterEvent('OnDistSettingsChange')



    def _OnMouseMove(self, *args):
        self.PrepareHint()



    def _OnClick(self, *args):
        sm.StartService('ui').StopBlink(self)
        if self.destroyed:
            uix.Flush(uicore.layer.menu)
            return 
        if (self.killsub and (type(self.action[1]) == list)):
            uthread.new(self.action[1][0][2][0][0], self.action[1][0][2][0][1][0])
            uix.Flush(uicore.layer.menu)
            return 
        if (type(self.action[1]) in types.StringTypes):
            sm.StartService('gameui').Say(self.action[1])
        else:
            try:
                apply(*self.action[1:])
            except Exception, e:
                uix.LogError(e, 'Failed executing action:', self.action)
                log.LogException()
                sys.exc_clear()
        uix.Flush(uicore.layer.menu)




